My compose-yaml has 3 services I am able to run the containers sucessfully when i am using docker-compose up. Now i want to build these 3 containers into single image. Is it possible? here is my compose-yaml
version: '2'
services:
tomcat:
container_name: tomcatcomposejdk
build: .
image: 'apexits/ubuntu-oracle-jdk8-tomcat9'
ports:
- "8787:8080"
- "5003:5003"
networks:
b:
ipv4_address: 10.5.0.6
expose:
- "8787"
- "5003"
mysql:
container_name: mysqlcompose
build: .
image: 'mysql:5.6.36'
ports:
- "3306:3306"
expose:
- "3306"
networks:
b:
ipv4_address: 10.5.0.7
environment:
MYSQL_DATABASE: "bird251"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
- ./BIRD251.sql:/tmp/BIRD251.sql
- ./import.sh:/tmp/import.sh
elasticsearch:
container_name: escompose
build: .
image: 'elasticsearch:2.3.4'
ports:
- "9200:9200"
- "9300:9300"
expose:
- "9200"
- "9300"
networks:
b:
ipv4_address: 10.5.0.8
networks:
b:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1
This is not recommended at all. You will need to reverse engineer each image and copy the needed binaries/files into the combined image. The approach for that is to use docker multistage build:
FROM apexits/ubuntu-oracle-jdk8-tomcat9 as tomcat
FROM mysql:5.6.36 as mysql
FROM elasticsearch:2.3.4
COPY --from=tomcat /.../tomcat-installtion .../tomcat-installation
COPY --from=mysql /.../mysql-installtion .../mysql-installation
...
This approach is very trick and you need to reverse engineer each image to figure out which files/folder/config need to be copied onto the combined image...
Alternatively, you can start from one of the images and install the other programs using standard installation guidelines for each.
Even if you are successful with that, you will need to start multiple processes in same container which is not recommended and will introduce many complexities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With