How to add a new container in a existing docker-compose file.
Steps:
The existing docker-compose file
version: '3.3'
networks:
pwa_net:
ipam:
driver: default
config:
- subnet: 60.0.0.0/24
gateway: 60.0.0.1
services:
mysql-cont:
image: mysql:8.0
container_name: springboot-mysql-cont
networks:
pwa_net:
ipv4_address: 60.0.0.11
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: bookstore
MYSQL_USER: bookstore
MYSQL_PASSWORD: bookstore
Stop all the running container just using dc stop
Then add the new container in the docker-compose file.
version: '3.3'
networks:
pwa_net:
ipam:
driver: default
config:
- subnet: 60.0.0.0/24
gateway: 60.0.0.1
services:
mysql-cont:
image: mysql:8.0
container_name: springboot-mysql-cont
networks:
pwa_net:
ipv4_address: 60.0.0.11
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: bookstore
MYSQL_USER: bookstore
MYSQL_PASSWORD: bookstore
redis-cont:
image: redis:latest
container_name: springboot-redis-cont
networks:
pwa_net:
ipv4_address: 60.0.0.14
Then start the new container just using dc up redis-cont
Then stop the container
Then start all the containers just using dc start
Posted by vasan to vasan's deck (2024-02-15 15:55)