Skip to content

example on how to start a docker compose environment in a (remote) docker host

Notifications You must be signed in to change notification settings

rgl/ubuntu-docker-compose-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Build

This is an example on how to start a docker-compose environment in a (remote) docker host.

NB This is similar to rgl/windows-docker-compose-example.

Usage

Execute the following commands:

# if required, set the DOCKER_HOST environment variable.
# this make the docker client use this dockerd.
# NB you must start dockerd with -H tcp://0.0.0.0:2375
#export DOCKER_HOST=tcp://10.1.0.2:2375

# create the environment defined in docker-compose.yml
# and leave it running in the background.
docker compose up --build -d

# show running containers.
docker compose ps

# execute command inside the containers.
docker compose exec -T hello ls -laF /
docker compose exec -T etcd etcd --version
docker compose exec -T etcd etcdctl version
docker compose exec -T etcd etcdctl endpoint health
docker compose exec -T etcd etcdctl put foo bar
docker compose exec -T etcd etcdctl get foo

# get the allocated hello port and create an endpoint url based in
# the DOCKER_HOST environment variable host.
hello_endpoint="$(
python3 <<'EOF'
import os
import urllib.parse
import subprocess

p = subprocess.Popen(
    ['docker', 'compose', 'port', 'hello', '8888'],
    text=True,
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
if 'DOCKER_HOST' in os.environ:
    docker_host_ip_address = urllib.parse.urlparse(os.environ['DOCKER_HOST']).netloc.split(':')[0]
    hello_port = stdout.strip().split(':')[-1]
    hello_endpoint = f'http://{docker_host_ip_address}:{hello_port}'
else:
    hello_endpoint = f'http://{stdout.strip()}'
print(hello_endpoint)
EOF
)"

# invoke the hello endpoint.
wget -qO- $hello_endpoint

# show logs.
docker compose logs

# destroy the environment.
docker compose down --volumes

About

example on how to start a docker compose environment in a (remote) docker host

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published