Compose is a tool for defining and running multi-container Docker applications.
Make Sure Docker installed & Swarm Cluster Configured.
yum install epel-release -y
yum install python-pip -y
pip install –upgrade pip
pip install docker-compose
mkdir Dockerfile
cd Dockerfile
vi Dockerfile
#Simple webserver
FROM centos:latest
LABEL maintainer=”test@gmail.com”
RUN yum install -y httpd
RUN echo “Container Website” >> /var/www/html/index.html
EXPOSE 80
ENTRYPOINT apachectl -DFOREGROUND
docker build -t myhttpd:v1 .
Sending build context to Docker daemon 2.048kB
Step 1/6 : FROM centos:latest
latest: Pulling from library/centos
……
……
……
Successfully built 5c316259c8c8
Successfully tagged myhttpd:v1
docker run -d –name testweb -p 80:80 myhttpd:v1
docker exec -it testweb /bin/bash
docker stop testweb
docker rm testweb
docker rmi myhttpd:v1
Testing Docker Compose:
vi /Dockerfile/docker-compose.yml
version: ‘3’
services:
apiweb1:
image: myhttpd:v1
build: .
ports:
– “81:80”
apiweb2:
image: myhttpd:v1
ports:
– “82:80”
load-balancer:
image: nginx:latest
ports:
– “80:80”
RUN Docker Compose against yml file docker-compose.yml in Local Directory
cd /Dockerfile
docker-compose up -d
……
Creating dockerfile_apiweb2_1 … done
Creating dockerfile_apiweb1_1 … done
Creating dockerfile_load-balancer_1 … done
If you get this error :
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.1) or chardet (2.2.1) doesn’t match a supported version!
Do the following:
pip uninstall chardet
pip uninstall urllib3
pip install chardet
pip install urllib3
docker ps
Now Check the Links
http://IP:81 http://IP:82 http://IP
docker-compose down –volumes ( take down the services)
docker stack deploy –compose-file docker-compose.yml mycustomstack (Stack deploy)