Docker Compose Hybrid
Docker Compose Hybrid (build + image)
The following blog shows example of a hybrid docker-compose file which build an image and also runs a side container
Create file "my-docker-compose-hybrid.yml" with the following contents
################
version: '2'
networks:
main:
services:
my-python-simplehttpserver:
container_name: my-python-simplehttpserver
build: ./python-simplehttpserver
ports:
- "9080:8080"
volumes:
- .:/var/www/
networks:
main:
aliases:
- my-python-simplehttpserver
my-mongo:
container_name: my-mongo
image: "mongo:3.2"
ports:
- "27017:27017"
networks:
main:
aliases:
- my-mongo
################
Create file "Dockerfile" under "python-simplehttpserver" directory with the following content:
########################
FROM ubuntu:latest
# Install python3
RUN apt-get update
RUN apt-get install -y python3
# Change to working directory
WORKDIR /var/www/
# Run http server on port 8080
EXPOSE 8080
CMD [ "python3", "-m", "http.server", "8080" ]
########################
Structure should look like this:
root-directory
|->my-docker-compose-hybrid.yml
|->python-simplehttpserver
|-> Dockerfile
Pull docker images:
docker-compose -f ./my-docker-compose-hybrid.yml -p mydockerhybridproject pull
Start docker services:
docker-compose -f ./my-docker-compose-hybrid.yml -p mydockerhybridproject up --build -d
Test Python Http Server form host machine:
curl -v -X GET "http://localhost:9080/my-docker-compose-hybrid.yml"
Test Python Http Server from mongo container:
docker exec -it my-mongo /bin/bash
apt-get update && apt-get install curl -y
curl -v -X GET "http://my-python-simplehttpserver:8080/my-docker-compose-hybrid.yml"
exit
Stop docker services:
docker-compose -f ./my-docker-compose-hybrid.yml -p mydockerhybridproject down -v
Comments
Post a Comment