Docker commands

Links

https://www.docker.com/

https://docs.docker.com/engine/installation/linux/ubuntulinux/

https://docs.docker.com/compose/install/

https://www.youtube.com/playlist?list=PLkA60AVN3hh_6cAz8TUGtkYbJSL2bdZ4h

https://examples.javacodegeeks.com/devops/docker/docker-tutorial-beginners/

Config

DNS (specific)

ubuntu before 16.04

sudo vim /etc/default/docker

DOCKER_OPTS=” — dns ip”

ubuntu after 16.04

sudo vim /etc/docker/daemon.json

{"dns": ["8.8.8.8", "8.8.4.4"]}

Basic Docker Commands

  • docker run
  • docker start
  • docker stop
  • docker kill
  • docker ps [-a include stopped containers]
  • docker ps — no-trunc=true // Don’t truncate output
  • docker rm
  • docker run — name webapp -p 8080:80
  • docker run -d // run in background
  • docker run -i busybox // Keep STDIN open even if not attached
  • docker run -t busybox // Allocate a pseudo-TTY
  • docker run -it — rm ubuntu // remove after exit
  • docker run ubuntu echo ‘it works’
  • docker exec containerId ip a // get container ip
  • docker inspect — format ‘{{.NetworkSettings.IPAddress}}’ containerId // get container ip
  • docker run — name wordpress1 — link mysql:mysql -d wordpress // link between wordpress and mysql
  • docker -itd //
  • docker atach nameId

logs

docker run -itd ubuntu uname -a
docker logs containerId

build docker

  • touch Dockerfile
➜  dockerTest tree
.
├── Dockerfile
└── html
└── index.html
1 directory, 2 files
FROM nginx
COPY html /usr/share/nginx/html
  • docker build -t radoslav/nginx-test
  • docker push radoslav/nginx-test // push to dockerhub

exec comands on containers

docker exec nameId ls

remove all containers

Stop all running containers

docker stop $(docker ps -q)
docker kill $(docker ps -q)

Delete all containers

docker rm $(docker ps -aq)

Delete all images

docker rmi $(docker images -q)

volumes

docker -it -v /files myimage 
docker -it -v /home/radoslav/files:/files myimage // mount files
docker -it -v /home/radoslav/files:/files:ro myimage // read only mount files
docker inspect nameId

search

More than 10 stars

docker search -s 10 ubuntu

Dockerfile (DSL to build images)

Basic

FROM ubuntu // what conainer to build from
RUN apt-get update // commands during build prosess
CMD ["pwd"] // commands exectutes when "docker run ..."
FROM ubuntu
RUN \
apt-get update && \
apt-get -y install apache2
ADD html/index.html /var/www/html/index.html
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

If port is EXPOSE “run -P” automatical port:port (80:80) docker run -itd -P conatinerId

FROM ubuntu
MAINTAINER radoslav <mail@mail.pl>
ENV VARIABLE_VERSION 1.0
VOLUME ["/var/www/html"]
WORKDIR /var/www/html
ADD html/index.html /var/www/html/index.html
RUN \
apt-get update && \
apt-get -y install apache2
EXPOSE 80
ENTRYPOINT ["/usr/sbin/apache2ctl"]
CMD ["-D", "FOREGROUND"]
Like what you read? Give Radosław Brzozowski a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.