1. An Introduction to Docker
1
Ruben Taelman - @rubensworks
imec - Ghent University
2. So what is Docker?
Platform for running software in isolated containers
2
3. So what is Docker?
Platform for running software in isolated containers
3
Traditional webserver
NGINX
PostgreSQL
Node
4. So what is Docker?
Platform for running software in isolated containers
4
Traditional webserver Docker webserver
NGINX
PostgreSQL
Node
NGINX
PostgreSQL
Node
5. So what is Docker?
Platform for running software in isolated containers
5
Traditional webserver Docker webserver
NGINX
PostgreSQL
Node
NGINX
PostgreSQL
Node
✓Linux ✓Windows ✓Mac
12. 12
# Inherit from the Node 4.2.2 image
FROM node:4.2.2
# Copy the server files
ADD . /app
# Install the node module
RUN cd /app && npm install
# Expose the default port
EXPOSE 3000
# Run base binary
ENTRYPOINT ["node", "bin/ldf-server"]
# Default command
CMD ["--help"]
> cat Dockerfile
13. RUN Executed when the image is being built
Zero or more RUN’s per Dockerfile
Typically used for installing software
Result will be stored in image
CMD Executed when the image is being run/instantiated
Only one CMD per Dockerfile
Default command to run when starting the container
Can be overridden by user
! Difference between RUN and CMD !
13
14. Build image to your local repository
Building a Dockerfile to an image
14
> docker build -t <image-name> <path-to-dir>
15. All your available images
Your local image repository
15
> docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ldf-server latest db3a7fb38cb2 10 minutes ago 683.3 MB
stuff latest do89d002jbsd 1 week ago 102.2 MB
17. Search the Docker hub, and download images to your local repo
Or use the command-line...
17
> docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating s... 4958 [OK]
ubuntu-upstart Upstart is an event-based replacement for ... 67 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 47 [OK]
> docker pull ubuntu
12.04: Pulling from library/ubuntu
ba2b457ecfb2: Pull complete
26180b0fe8fb: Pull complete
edd7c1974a70: Pull complete
57bca5139a13: Pull complete
library/ubuntu:12.04: The image you are pulling has been verified.
Status: Downloaded newer image for ubuntu:12.04
18. Instantiate an image
Running an image
18
> docker run -it --rm ldf-server
Important options:
-i
-t
--rm
-d
-p 8080:80
-v /mydir:/targetdir
...
Keep STDIN open
Allocate new terminal
Remove container after stopping (default: stopped state)
Run in background
Map host port to container port
Map local directory to container directory
19. List running containers
List running + stopped containers
Stop container
Remove container
List images
Remove image
Image and container management
19
docker ps
docker ps -a
docker stop <container-hash-or-name>
docker rm <container-hash-or-name>
docker images
docker rmi <image-name>
20. Attach an image (not guaranteed to have a CLI)
Using detached containers
20
> docker attach <container-hash>
Open shell in container (useful for debugging)
> docker exec -it <container-hash> /bin/bash
CTRL+p CTRL+q to detach