Skip to content

saeedhosseini21/docker-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Visits Badge GitHub license GitHub stars

A list of common tasks in docker

docker-cheatsheet

Task 1:

Get mysql:8 image and specify ports, volumes and docker version by which the image is built.

Answer:

docker pull mysql:8

docker inspect

Task 2:

  1. Get nginx:latest image and save it to a local file. then load it using load and import commands.

    Answer:

     docker pull nginx:latest
     docker save nginx:latest -o nginx.tar
     docker load -i nginx.tar    
     docker import nginx.tar nginx:2
    
  2. explain differences between LOAD and IMPORT commands

    Answer:

    LOAD command loads the image with no changes while IMPORT merges all the layers, erases all the history and metadata of the image.

Task3:

Run a nginx container and bind it to port 8081 of the host.

Answer:

docker run -p 8081:80 nginx

Task4:

Find the number of running processes of the container run in the previous task.

Answer:

docker top nginx | nl

Task5:

Run an alpine container and install nginx on it, then make a docker image out of it.

Answer:

 docker run --rm -it --name alpine alpine

In the container:

 apk add nginx

In the host:

 docker commit alpine alpine:nginx

Task6:

Run a redis container then write it's id in a file named myredis.cid

Answer:

 docker run -d --name redis redis > myredis.cid
 docker container inspect -f '{{ .Id }}' redis > myredis.cid

Task7:

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.

Answer:

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

Task8:

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.

Answer:

docker run --name alpine -it -e CLASS=dws -e NAME=saeed alpine
echo $NAME & echo $CLASS

Task9:

Run an alpine container, bind an arbitrary path in the host to /data of the container. Aslo change the container WorkingDir this mounted path.\

Answer:

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

About

docker-cheatsheet

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published