Professional Documents
Culture Documents
Docker Basics
Docker Basics
Docker Basics
Images
Pulling images
Containers
Running containers
Exposing ports
Run a container and map the host port to the container's port: docker run -p <host_port>:<container_port>
<image>
Map multiple ports: docker run -p <host_port_1>:<container_port_1> -p <host_port_2>:
<container_port_2> <image>
Managing containers
Naming containers
Volumes
Create a volume: docker run -v <path_on_host>:<path_on_container>:<options> <image>
Options can be:
ro: read only
Go inside a container: docker exec -it <container_id|container_name> <command>
Dockerfile
Example of a Dockerfile:
FROM nginx:latest
ADD . /usr/share/nginx/html
Building Dockerfile
FROM node:latest
# If there is a folder called "app" use it, otherwise create a new one
WORKDIR /app
ADD . .
RUN npm install
CMD node index.js
.dockerignore
Example:
node_modules
Dockerfile
.git
Caching
Suppose we have this Dockerfile :
FROM node:latest
WORKDIR /app
ADD . .
RUN npm install
CMD node index.js
Alpine
To get latest alpine version of an image (works almost on all cases): docker pull <image>:alpine
Example:
FROM nginx:1.17.2-alpine
Tag an image
Docker registries
Highly scalable server side application that stores and lets you distribute Docker images
Used in your CI/CD pipeline
Run your applications
To push an image you first need to login with docker login . Then you have to docker push according to the instructions
given by Docker Hub or other container registry service.
Docker inspect
To inspect a container: docker inspect <container_id>
Docker logs
To see the logs of a container: docker logs <container_id>
To follow the logs: docker logs -f <container_id>
Docker exec
To go insider a container: docker exec -it <container_id|container_name> <command>