0

I am not an advance user so please bear with me.

I am building a docker image using docker-compose -f mydocker-compose-file.yml ... on my machine.

The image then been pushed to a remote docker registry.

Then from a remote server I pull down this image.

To run this image; I have to copy mydocker-compose-file.yml from my machine to remote server and then run docker-compose -f mydocker-compose-file.yml up -d.

I find this very inefficient as why I need the same YAML file to run the docker image (should I?).

Is there a way to just spin up the container without this file from remote machine?

2 Answers 2

1

As of compose 1.24 along with the 18.09 release of docker (you'll need at least that client version on the remote host), you can run docker commands to a remote host over SSH.

# all docker commands in this shell will not talk to the remote host
export DOCKER_HOST=ssh://user@host
# you can verify that with docker info to see which engine you're talking to
docker info
# and now run your docker-compose up command locally to start/stop containers
docker-compose up -d

With previous versions, you could configure TLS certificates to allow specific clients to connect to the docker API over a network connection. See these docs for more details.

Note, if you have host volumes, the variables and paths will be expanded to your laptop directories, but the host mounts will happen on the remote server where those directories may not exist. This is a good situation to switch to named volumes.

Sign up to request clarification or add additional context in comments.

Comments

1

Everything you can do with Docker Compose, you can do with plain docker commands.

Depending on how exactly you're interacting with the remote server, your tooling might have native ways to do this. One specific example I'm familiar with is the Ansible docker_container module. If you're already using a tool like Ansible, Chef, or Salt, you can probably use a tool like this to do the same thing your docker-compose.yml file does.

But otherwise there's more or less a direct translation between a docker-compose.yml file

version: '3'
services:
  foo:
    image: me/foo:20190510.01
    ports: ['8080:8080']

and a command line

docker run -d --name foo -p 8080:8080 me/foo:20190510.01

My experience has been that the docker run commands quickly become unwieldy and you want to record them in a file; and once they're in a file, you start to wish they were in a more structured format, even if you need an auxiliary tool to run them; which brings you back to copying around the docker-compose.yml file. I think that's pretty routine. (Something needs to tell the server what to run.)

2 Comments

I understand this part but when I build the image using that file, doesnt/shouldn't have all the stuff needed to run the container? I think there is a flow in my understanding but I think, you build the image using one set of instruction (which you declare in .yml) and from that point onward you should just need to do docker run -d <imageId>. But it seems like this isnt the case?
Settings like port mappings, host volume mounts, and the like can't be set in an image; they have to go on the docker run command line, or set by whatever other tool launches the container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.