I can somehow handle a docker engine but cannot handle a docker compose.
I have two docker images which is pg13ondeb and pyonol8. The one is originaly from postgresql13 image and the other is from OracleLinux8 which has my python script to write data into pq13 database.
I confirmed that 2 containers which are started with these images were able to co-work, I mean INSERT INTO SQL. The script is executed manualy from terminal.
The two containers are maked with following docker commands.
docker run --name pg13_1 -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d pg13ondeb
docker run --name client1 -it pyonol8 /bin/bash
(As you see, 1st command has -d option and the 2nd command does not.)
Now, I want to create one pg13server container and 2client python containers by docker compose command. In order to do so, I write a following yml file and performed it.
version: "3"
services:
pg13ondeb_1:
image: pg13ondeb
ports:
- "5432:5432"
networks:
pg_net_1:
ipv4_address: 172.20.0.2
pyonol8_1:
image: pyonol8
networks:
pg_net_1:
ipv4_address: 172.20.0.11
pyonol8_2:
image: pyonol8
networks:
pg_net_1:
ipv4_address: 172.20.0.12
networks:
pg_net_1:
name: app_net
driver: bridge
ipam:
driver: default
config:
- subnet: 172.20.0.0/24
Then I executed this as below.
> docker compose up -d
[+] Running 4/4
⠿ Network app_net Created 0.0s
⠿ Container compose-pyonol8_1-1 Started 0.7s
⠿ Container compose-pyonol8_2-1 Started 0.8s
⠿ Container compose-pg13ondeb_1-1 Started 0.8s
It seems like be done. I checked it with dicker ps -a
and three containers were appeared. However, when I did it with docker ps
, only compose-pg13ondeb_1-1 is appeared. Which means other two clients which are supposed to be started are not actually started.
My hunch says that the -d oprion resulted this. Does somebody know how to resolve this in yml file?
Thank you,
2
Answers
docker ps -a
and check logs ofpyonol8_1-3
containers bydocker logs <container>
. If there is error fix it.pyonol8
entrypoint command, may be it finished and conatiner was stoped after finish script.As hinted by the
services:
label, Compose is a little more designed around long-running non-interactive containers. If you have a mix of long-running and temporary containers, you should only put the long-running containers in yourdocker-compose.yml
file.Then you can run your temporary containers connecting to that network explicitly.
If the image’s standard
CMD
does actually have a long-running process, and you’re just creating a second temporary container with a debugging shell, thendocker-compose run
will give you a container mostly based on Compose configuration, but ignoringports:
and running some different command. You could then include the container in the Compose setup(Throughout this I’ve significantly simplified the network configuration. Compose provides a network named
default
for you, and Docker will automatically assign IP addresses, so in most cases you don’t neednetworks:
settings in your Compose file at all. Also see Networking in Compose in the Docker documentation.)