0% found this document useful (0 votes)
11 views

Docker Memo

docker short commands
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Docker Memo

docker short commands
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Install Docker on Ubuntu 14.

04 (it should work also with small adaptations on


Ubuntu 16.04)
---------------------------------------------------------------

sudo su

apt update

apt-get install apt-transport-https ca-certificates

apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys


58118E89F3A912897C070ADBF76221572C52609D

nano /etc/apt/sources.list.d/docker.list
and write into the file:
deb https://apt.dockerproject.org/repo ubuntu-trusty main

apt-get update

apt-get purge lxc-docker

apt-cache policy docker-engine

apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

apt-get install docker-engine

service docker start

groupadd docker

exit
sudo usermod -aG docker $USER

Follow instructions from here


https://docs.docker.com/compose/install/
to install docker-composer on Ubuntu.

How to use nodejs container


-----------------------------

go to the project folder:


cd /home/andrei/Projects/var/angular2/angular2-tour-of-heroes

copy file docker-compose.yml to project's folder (find file docker-compose.yml in


the same folder as this file docker-memo.doc )

create folder for docker in the project's folder:


mkdir -p docker/node (this path is just configured in file docker-compose.yml)

build and start the docker container


sudo docker-compose up -d --build --force-recreate
- at the end of the output if previous command you will see something like:
“Creating angular2tourofheroes_node_1”
- I think angular2tourofheroes_node_1 is the name of the docker container

see the running docker containers


sudo docker ps (--all for all containers not just running)

What is the difference between CMD and ENTRYPOINT


in a Dockerfile?
The documentation states for CMD
The main purpose of a CMD is to provide defaults for an executing
container.
and for ENTRYPOINT:
An ENTRYPOINT helps you to configure a container that you can run as an
executable.
Explanation:

Docker has a default entrypoint which is /bin/sh -c but does not have a default
command.
When you run docker like this: docker run -i -t ubuntu bash the entrypoint is the
default /bin/sh -c, the image is ubuntu and the command is bash.
The command is run via the entrypoint. i.e., the actual thing that gets executed
is /bin/sh -c bash. This allowed docker to implement RUN quickly by relying on the
shell's parser. Later on, people asked to be able to customize this so ENTRYPOINT and -
entrypoint has been introduced.
Everything after ubuntu in the example above is the command and is passed to the
entrypoint. When using the CMD instruction, it is exactly as if you were doing docker
run -i -t ubuntu <cmd>. <cmd> will be the parameter of the entrypoint.
You will also get the same result if you instead type this command docker run -i -t
ubuntu. You will still start a bash shell in the container because of the ubuntu
Dockerfile specified a default CMD: CMD ["bash"]
As everything is passed to the entrypoint, you can have a very nice behavior from
your images. @Jiri example is good, it shows how to use an image as a "binary".
When using ["/bin/cat"] as entrypoint and then doing docker run img /etc/passwd,
you get it, /etc/passwd is the command and is passed to the entrypoint so the end
result execution is simply /bin/cat /etc/passwd.
An other example would be to have any cli as entrypoint. For instance, if you have a
redis image, instead of running docker run redisimg redis -H something -u toto get
key, you can simply have ENTRYPOINT ["redis", "-H", "something", "-u", "toto"] and
then run like this for the same result: docker run redisimg get key.

Attach to the docker container (like connecting to the virtual machine): run bash
in the container
docker exec -i -t angular2tourofheroes_node_1 /bin/bash

for configurations changes, edit file docker-compose.yml which you


copied to the project's folder and rebuild/restart the container by
running:
sudo docker-compose -f docker-compose.yml build –no-cache
sudo docker-compose -f docker-compose.yml up -d

or in one command:
docker-compose up -d --build --force-recreate

see the output of a running docker container:


docker logs -f -t --details marshme_php_apache_1

Stop 2 docker containers


sudo docker rm -f angularupcall_nginx_1 angularupcall_node_1

# Stop all containers


docker stop $(docker ps -a -q)

#remove all networks


docker network rm $(docker network ls | awk '/ / { print $1 }')

# Delete all containers


docker rm $(docker ps -a -q)

# Delete all images not used by a running container


docker rmi $(docker images -a --filter=dangling=true -q)

# Delete all images


docker rmi $(docker images -q) --force
Remove unused data (images)
docker system prune

docker run --rm \


-e [email protected] \
-e MAIL_PASS=marshmailpassword \
-ti tvial/docker-mailserver:latest \
/bin/sh -c 'echo "$MAIL_USER|$(doveadm pw -s SHA512-CRYPT -u $MAIL_USER -p
$MAIL_PASS)"' >> mail/config/postfix-accounts.cf

docker run --rm \


-v "$(pwd)/mail/config":/tmp/docker-mailserver \
-ti tvial/docker-mailserver:latest generate-dkim-domain marsh.com

You might also like