Docker Compose

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you create and start all the services from your configuration.

Install Docker Compose

https://github.com/docker/compose/releases

[root@jenkins ~]# curl -o /usr/local/bin/docker-compose -L “https://github.com/docker/compose/releases/download/1.15.0/docker-compose-$(uname -s)-$(uname -m)”
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 36 0 –:–:– 0:00:16 –:–:– 142
100 8650k 100 8650k 0 0 93774 0 0:01:34 0:01:34 –:–:– 551k

[root@jenkins ~]# chmod +x /usr/local/bin/docker-compose

[root@jenkins ~]# docker-compose –version
docker-compose version 1.15.0, build e12f3b9

[root@jenkins ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE

[root@jenkins ~]# mkdir hello-world/

[root@jenkins ~]# cd hello-world/

[root@jenkins hello-world]# vim docker-compose.yml
my-test:
image: hello-world

[root@jenkins hello-world]# docker-compose up
Pulling my-test (hello-world:latest)…
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest
Creating helloworld_my-test_1 …
Creating helloworld_my-test_1 … done
Attaching to helloworld_my-test_1
my-test_1 |
my-test_1 | Hello from Docker!
my-test_1 | This message shows that your installation appears to be working correctly.
my-test_1 |
my-test_1 | To generate this message, Docker took the following steps:
my-test_1 | 1. The Docker client contacted the Docker daemon.
my-test_1 | 2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
my-test_1 | 3. The Docker daemon created a new container from that image which runs the
my-test_1 | executable that produces the output you are currently reading.
my-test_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it
my-test_1 | to your terminal.
my-test_1 |
my-test_1 | To try something more ambitious, you can run an Ubuntu container with:
my-test_1 | $ docker run -it ubuntu bash
my-test_1 |
my-test_1 | Share images, automate workflows, and more with a free Docker ID:
my-test_1 | https://cloud.docker.com/
my-test_1 |
my-test_1 | For more examples and ideas, visit:
my-test_1 | https://docs.docker.com/engine/userguide/
my-test_1 |
helloworld_my-test_1 exited with code 0

[root@jenkins hello-world]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 1815c82652c0 2 months ago 1.84kB

[root@jenkins hello-world]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@jenkins hello-world]# docker run -it hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

[root@jenkins hello-world]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6f6b4742d96 hello-world “/hello” 26 seconds ago Exited (0) 24 seconds ago hungry_blackwell
413afefd5a74 hello-world “/hello” About a minute ago Exited (0) About a minute ago helloworld_my-test_1

 

Leave a comment