Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run docker-compose on remote host?

I have compose file locally. How to run bundle of containers on remote host like docker-compose up -d with DOCKER_HOST=<some ip>?

like image 367
Arsen Avatar asked Feb 16 '16 12:02

Arsen


People also ask

How do I run a Docker container on remote host?

Setting Up The Remote Host Remote access requires a TCP socket. Run dockerd (the Docker daemon executable) with the -H flag to define the sockets you want to bind to. This command will bind Docker to the default Unix socket and port 2375 on your machine's loopback address.

Can I deploy Docker compose?

You can use Compose to deploy an app to a remote Docker host by setting the DOCKER_HOST , DOCKER_TLS_VERIFY , and DOCKER_CERT_PATH environment variables appropriately. See also Compose CLI environment variables.


2 Answers

After the release of Docker 18.09.0 and the (as of now) upcoming docker-compose v1.23.1 release this will get a whole lot easier. This mentioned Docker release added support for the ssh protocol to the DOCKER_HOST environment variable and the -H argument to docker ... commands respectively. The next docker-compose release will incorporate this feature as well.

First of all, you'll need SSH access to the target machine (which you'll probably need with any approach).

Then, either:

# Re-direct to remote environment. export DOCKER_HOST="ssh://my-user@remote-host"  # Run your docker-compose commands. docker-compose pull docker-compose down docker-compose up  # All docker-compose commands here will be run on remote-host.  # Switch back to your local environment. unset DOCKER_HOST 

Or, if you prefer, all in one go for one command only:

docker-compose -H "ssh://my-user@remote-host" up 

One great thing about this is that all your local environment variables that you might use in your docker-compose.yml file for configuration are available without having to transfer them over to remote-host in some way.

like image 187
Dirk Avatar answered Sep 30 '22 07:09

Dirk


If you don't need to run docker container on your local machine, but still on the same remote machine, you can change this in your docker setting.

On the local machine: You can control remote host with -H parameter

docker -H tcp://remote:2375 pull ubuntu 

To use it with docker-compose, you should add this parameter in /etc/default/docker

On the remote machine

You should change listen from external adress and not only unix socket.

See Bind Docker to another host/port or a Unix socket for more details.

If you need to run container on multiple remote hoste, you should configure Docker Swarm

like image 27
Thibaut Avatar answered Sep 30 '22 07:09

Thibaut