I was previously running the Docker container for my web application below:
echo Starting postgres container...
docker run -d -p 5432:5432 --name db my_db
echo Postgres container started
echo Starting memcached container...
docker run -d -p 11211:11211 --name mem memcached
echo Memcached container started
echo Starting web container...
docker run -d -p 8000:8080 --name web --link db:postgres --link mem:memcache my_web_app
echo Web container started
echo Waiting for tomcat to initialize...
sleep 5
echo curling logon.jsf
curl http://111.111.11.111:8000/app/logon.jsf #Real URL redacted
echo Application started
Which became the below docker-compose script:
version: '2'
services:
web:
image: tomcat:7.0.69-jre8
build: ./ci
ports:
- "8000:8080"
depends_on:
- db
- mem
db:
image: postgres:9.4.7
build: ./db
ports:
- "5432:5432"
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
mem:
image: memcached
ports:
- "11211:11211"
When I launch the container, it seems like postgres is no longer running (Connection refused, netstat -al | grep postgres doesn't show it), and thus, the app doesn't work. I reviewed the change I have made, and realized that the docker-compose.yml has no analog for the tomcat sleep and curl command I had given in the run script - should it? I couldn't find any information online regarding a proper analog. Is something else potentially afoot here? Please advise if any further details are required.
EDIT: docker ps yields:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a942be02fc22 tomcat:7.0.69-jre8 "catalina.sh run" 5 minutes ago Up About a minute 0.0.0.0:8000->8080/tcp memcachedocker_web_1
fd6074cf8ec9 postgres:9.4.7 "/docker-entrypoint.s" 5 minutes ago Up About a minute 0.0.0.0:5432->5432/tcp memcachedocker_db_1
ce18771fee28 memcached "/entrypoint.sh memca" 5 minutes ago Up About a minute 0.0.0.0:11211->11211/tcp memcachedocker_mem_1
and the logs for the container:
Success. You can now start the database server using:
postgres -D /var/lib/postgresql/data
or
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....LOG: database system was shut down at 2016-06-01 13:09:23 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
done
server started
CREATE DATABASE
CREATE ROLE
/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
CREATE DATABASE
LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
waiting for server to shut down....LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2016-06-01 13:09:25 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
and thus inside the container, :
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.11:44095 0.0.0.0:* LISTEN
tcp 0 0 172.18.0.4:38868 132.246.2.23:80 TIME_WAIT
tcp 0 0 172.18.0.4:36424 5.153.231.35:80 TIME_WAIT
tcp6 0 0 127.0.0.1:8005 :::* LISTEN
tcp6 0 0 :::8009 :::* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
tcp6 0 0 172.18.0.4:47522 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47518 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47524 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47520 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47516 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47514 172.18.0.2:11211 ESTABLISHED
udp 0 0 172.18.0.4:48360 10.0.2.3:53 ESTABLISHED
udp 0 0 127.0.0.11:40276 0.0.0.0:*
We can see that the memcached container is up and running, however postgres is absent. The only thing running on the localhost interface is bound to 8005, and it isn't postgres. I should add finally that I am able to telnet memcached on its port from the web container and confirm its operation, however I can't do the same with postgres, and I'm not sure why.
docker ps
(ordocker-compose ps
) is for. And if it has faileddocker logs
might show you why. Also, something is terribly wrong with the indentation of thedocker-compose.yml
document you posted; if you take a moment to clean it up, you'll avoid answers along the lines of "that couldn't possibly work". – larsks Jun 1 '16 at 13:08