Docker cheat sheet
CPU Constraints
You can limit CPU, either using a percentage of all CPUs, or by using specific cores.
For example, you can tell the
cpu-shares
setting. The setting is a bit strange -- 1024 means 100% of the CPU, so if you want the container to take 50% of all CPU cores, you should specify 512:docker run -it -c 512 agileek/cpuset-test
docker run -it --cpuset-cpus=0,4,6 agileek/cpuset-test
Note that Docker can still see all of the CPUs inside the container -- it just isn't using all of them.
Memory Constraints
docker run -it -m 300M ubuntu:14.04 /bin/bash
Import a container as an image from file:
cat my_container.tar.gz | docker import - my_image:my_tag
Export an existing container:
docker export my_container | gzip > my_container.tar.gz
-
docker save
saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7).
Load an image from file:
docker load < my_image.tar.gz
Save an existing image:
docker save my_image:my_tag | gzip > my_image.tar.gz
- EXPOSE informs Docker that the container listens on the specified network ports at runtime. NOTE: does not actually make ports accessible.
- ADD copies new files, directories or remote file to container. Invalidates caches. Avoid
ADD
and useCOPY
instead. - COPY copies new files or directories to container. By default this copies as root regardless of the USER/WORKDIR settings. Use
--chown=<user>:<group>
to give ownership to another user/group. (Same forADD
.)
-
docker network rm
NAME Remove one or more networks by name or identifier. No containers can be connected to the network when deleting it.
.
.
.
------
Last modified 3yr ago