Docker

+

Docker Compose

Docker

Why would I use it?

Easy Environment Replication

$ docker pull <image_name>
$ docker run <image_name>

+

=

The same environment, wherever you run it

Lightweight

Docker shares and reuses a lot of resources

Easy to plug services

If there is an image for the service, all you have to do is download and run it.

How does it work?

Docker allows you to package an application with all of its dependencies into a standardized unit for software development.

https://www.docker.com/what-docker

Debian + PostgreSQL

IMAGES

(aka "standardized unit for software development")

CONTAINERS

Debian + PostgreSQL

Running the Postgresql

Debian + PostgreSQL

Running the Postgresql

Let's use it

Downloading images

$ docker pull postgres

Running a container

$ docker run --name db postgres

Linking Containers

$ docker run -it --link db postgres \
  sh -c 'psql -h $DB_PORT_5432_TCP_ADDR -U postgres'

Listing Containers

$ docker ps

CONTAINER ID IMAGE    [...] STATUS       PORTS    NAMES
f34bd9bf7083 postgres [...] Up 2 minutes 5432/tcp angry_turing        
c12b2e87c42b postgres [...] Up 2 minutes 5432/tcp db                  

Note: To list stopped containers, use the -a option

Lets build our image

FROM <base_image>
RUN apt-get install <some dependencies>
...

Defining the image:

Dockerfile

$ docker build -t my_image_name .

Building your image

$ docker images

REPOSITORY    TAG    IMAGE ID     CREATED      VIRTUAL SIZE
my_image_name latest 227510c3fed6 1 minute ago XYZ.X MB

Listing Images

Docker Compose

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

https://docs.docker.com/compose

db:
  image: postgres
web:
  build: .
  ports:
   - "3000:3000"
  volumes:
   - .:/code
  links:
   - db

Defining your application and its dependencies:

docker-compose.yml

$ docker-compose up

Running your application

Thanks

Docker + Docker Compose Day 3.0

By Tarun Sharma

Docker + Docker Compose Day 3.0

  • 1,045