A list of common tasks in docker
Get mysql:8 image and specify ports, volumes and docker version by which the image is built.
docker pull mysql:8
docker inspect
-
Get nginx:latest image and save it to a local file. then load it using load and import commands.
docker pull nginx:latest docker save nginx:latest -o nginx.tar docker load -i nginx.tar docker import nginx.tar nginx:2
-
explain differences between LOAD and IMPORT commands
LOAD command loads the image with no changes while IMPORT merges all the layers, erases all the history and metadata of the image.
Run a nginx container and bind it to port 8081 of the host.
docker run -p 8081:80 nginx
Find the number of running processes of the container run in the previous task.
docker top nginx | nl
Run an alpine container and install nginx on it, then make a docker image out of it.
docker run --rm -it --name alpine alpine
In the container:
apk add nginx
In the host:
docker commit alpine alpine:nginx
Run a redis container then write it's id in a file named myredis.cid
docker run -d --name redis redis > myredis.cid
docker container inspect -f '{{ .Id }}' redis > myredis.cid
Run a nginx container which is limited to CPU=1.5core, Memory=512M and Swap=256M. Also the container's processes must only be run on cores number 0 and 2.
docker run --rm -it --name nginx --memory=512m --memory-swap=768m --cpus="1.5" --cpuset-cpus=0,2 nginx:latest
Note: --memory-swap = maximum_memory + maximum_swap
Run an alpine container and set CLASS=dws and NAME=saeed as enviroment variables in the container. Then in the container, display these two enviroment variables.
docker run --name alpine -it -e CLASS=dws -e NAME=saeed alpine
echo $NAME & echo $CLASS
Run an alpine container, bind an arbitrary path in the host to /data of the container. Aslo change the container WorkingDir this mounted path.\
docker run --rm -it --name alpine -v /home/saeed/test:/data --workdir /data alpine
@dwsclass dws-ops-004-docker
@dwsclass dws-ops-005-docker
@dwsclass dws-ops-006-docker
@dwsclass dws-ops-007-docker