Docker Commands

Docker Commands

  • docker –version
  • docker pull <image name>
  • docker run -it -d <image name>
  • docker exec -it <container id> bash : This command is used to access the running container
  • docker ps
  • docker ps -a
  • docker stop <container id>
  • docker kill <container id>
  • docker commit <conatainer id> <username/imagename>
  • docker push <username/image name>
  • docker images
  • docker rm <container id>
  • docker rmi <image-id>
  • docker build <path to docker file>

Docker Compose

Compose is a tool for defining and running multi-container Docker applications.

With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. This file is called docker compose file.

Compose works in all environments: production, staging, development, testing, as well as CI workflows

Using Compose is basically a three-step process:

  1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
  2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
  3. Run docker-compose up and Compose starts and runs your entire app.

A docker-compose.yml looks like this:

version: '3'
services:
  web:
    build: .
    ports:
    - "5000:5000"
    volumes:
    - .:/code
    - logvolume01:/var/log
    links:
    - redis
  redis:
    image: redis
volumes:
  logvolume01: {}