Docker-compose Run Results In Connection Refused

Docker-compose Run Results In Connection Refused

Estimated reading time: 2 minutes Docker compose run

To execute the docker-compose.yml file, you need to run a very simple command: docker-compose up. Docker Compose Workflow. Below are the three steps to use docker-compose. Create dockerfile of each service; Create a docker-compose.yml file to connect all the dockerfiles; Run docker-compose up command to start the system. Docker Compose simplifies multi-container Docker environments on a single host. Let’s put together a basic web app with Docker Compose and Flask using Redis (we end up with a Python/Flask container and a Redis container all on one host). We do not need custom networking or to design our own networks to run on; Compose does everything for us!

You can control the order of service startup and shutdown with thedepends_on option. Compose always starts and stopscontainers in dependency order, where dependencies are determined bydepends_on, links, volumes_from, and network_mode: 'service:..'.

However, for startup Compose does not wait until a container is “ready” (whatever that meansfor your particular application) - only until it’s running. There’s a goodreason for this.

The problem of waiting for a database (for example) to be ready is really justa subset of a much larger problem of distributed systems. In production, yourdatabase could become unavailable or move hosts at any time. Your applicationneeds to be resilient to these types of failures.

To handle this, design your application to attempt to re-establish a connection tothe database after a failure. If the application retries the connection,it can eventually connect to the database. Winuae kick rom 1.3.

The best solution is to perform this check in your application code, both atstartup and whenever a connection is lost for any reason. However, if you don’tneed this level of resilience, you can work around the problem with a wrapperscript:

  • Use a tool such as wait-for-it,dockerize, or sh-compatiblewait-for. These are smallwrapper scripts which you can include in your application’s image topoll a given host and port until it’s accepting TCP connections.

    For example, to use wait-for-it.sh or wait-for to wrap your service’s command:

    Tip: There are limitations to this first solution. For example, it doesn’t verify when a specific service is really ready. If you add more arguments to the command, use the bash shift command with a loop, as shown in the next example.

  • Alternatively, write your own wrapper script to perform a more application-specific healthcheck. For example, you might want to wait until Postgres is definitelyready to accept commands:

    You can use this as a wrapper script as in the previous example, by setting:

Compose documentation

documentation, docs, docker, compose, startup, shutdown, order

The docker compose reference, 3.2, defines port mode as the following: 'mode: host for publishing a host port on each node, or ingress for a swarm mode port to be load balanced.' However, publishing ports using the host mode results in 'connection refused' via netcat, etc. Note, the port can be connected to via localhost/127.0.0.1 from the machine on which the container is running and the service is listening on target port within the container. The container does appear to map the port correctly - 0.0.0.0:XXXX->YYYY/tcp - to the host at 0.0.0.0 and not 127.0.0.1 as verified by 'docker ps -a ' and 'docker inspect '. The following is an example of a published port in the docker compose 3.2 file:

The overlay network is needed for normal service communication. The host ports are needed for external container monitoring software, e.g., which requires direct access to each container (not the service).

Why are the published ports to the host this not working as defined?

The following is the relevant docker info:

Refused

Server Version: 18.03.1-ce
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
NodeID: odi9elwexmd6fqmkg02m4akic
Is Manager: false
Node Address: 10.0.0.14
Manager Addresses:
10.0.0.9:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.15.10-300.fc27.x86_64
Operating System: Fedora 27 (Atomic Host)

Docker-compose Run Results In Connection Refused
© 2020