Docker Basic Commands
Docker Basic Commands
Docker Basic Commands
Docker Hub
• Docker commit <container id> <name you want to give to new image> {To create an
image from contained with needed changes according to user}
• Docker login
• Extension: {enter your username and password}
• Docker push <image name you want to push>
Docker file
Docker can build images by reading set of instructions in side a docker file.
Sample file with name dockerfile
FROM ubuntu
ADD . /var/www/html
Bind mount has limited functionality compared to volumes. When we use this, a file or directory
on the host machine is mounted into a container.
• Docker run -it -v <path local>:<path in docker> <inage name>
• Docker run -it -v /home/user/desktop/dockerfile:/var/www/html ubuntu
Docker volumes
Unlike Bind Mount a new directory is created within docker storage directory on the host
machine, and docker will manage that contents.
• Docker volume create <name>
• Ex: Docker volume create data
• Docker run -it - -mount source=<name of volume>,target=<path> <image name>
• Docker run -it - -mount source=data,target=/var/www/html ubuntu
Docker Compose
Docker compose is used to run multiple containers, by reading a config Docke-compose.yml file.
With a single command, you create and start all the services from your configuration.
• Docker-compose.yaml
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Docker Swarm