Dino Geek, try to help you

How to configure memory and CPU for a Docker container?


Configuring memory and CPU for a Docker container can be done using the Docker client at the time of starting the container. A Docker container does not have a maximum limit for CPU, memory, or storage by default.

Here’s how you can configure the memory and CPU for a Docker container:

1. Memory:
To limit a container’s memory usage, use the `-m` or `—memory` flag with the `docker run` command. For example:

```
docker run -it -m 500m ubuntu
```
Here we are configuring the started Docker container to use a maximum of 500MB of memory.

1. CPU:
To limit a container’s CPU usage, you can use the `—cpus` flag. This will limit the container’s access to the number of CPUs you specify. For example:

```
docker run -it —cpus 1.5 ubuntu
```
Here we are configuring the started Docker container to use a maximum of 1.5 CPUs.

1. Another way to limit a container’s CPU usage is with the `—cpu-shares` flag. For instance:

```
docker run -it —cpu-shares 2048 ubuntu
```
Here we are giving the Docker container a relative weight of 2048.

1. You can also control a container’s access to CPU by using `—cpuset-cpus` flag. Example:

```
docker run -it —cpuset-cpus 0-3 ubuntu
```
In this case, your container will only be able to use CPU cores 0 to 3.

Please keep in mind that CPU shares or limits only get enforced when there is CPU contention.

Your container will use as much as it needs when there is no contention for the CPU.

Remember, the Docker container would be allowed to utilize as much CPU or memory as available on the Docker host by default – and therefore, setting the limits correctly allows many Docker containers to co-exist on the same host in a balanced manner.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use