<h3>Approach 1: SSH and Remote Docker Commands</h3>
<p>This approach involves SSHing into your Linode server and manually running <code>git pull</code> and <code>docker-compose up</code> commands. This is a straightforward method but can be cumbersome to automate and manage.</p>
<pre><code>deploy:
  stage: deploy
  script:
    - ssh deployer@xxx.xxxxx.dev &quot;cd /path/to/your/project &amp;&amp; git pull &amp;&amp; docker-compose up -d&quot;
</code></pre>
<h3>Approach 2: Docker Context</h3>
<p>Using Docker Context allows you to manage Docker endpoints easily and execute commands on remote Docker hosts without manually SSHing into them</p>
<pre><code>testcontext-job:
  stage: testcontext
  image: docker:latest
  script:
    - docker context create remote --docker &quot;host=ssh://deployer@xxx.xxxxx.dev&quot;
    - docker context use remote
    - docker context ls
</code></pre>
<pre><code>deploy:
  stage: deploy
  image: docker:latest
  script:
    - docker context use remote
    - docker-compose up -d
</code></pre>
<h4>Be careful</h4>
<p>Don't forget the quotations in your <code>docker create context</code> comment.</p>

CC BY-SA 4.0
2024-08-17T15:20:17.903Z
2024-08-17T15:20:17.903Z
YassineLbk
<p>New to the Devop world so my terminology may be limited or incorrect. I have a self-hosted gitlab server. I had a &quot;hello world&quot; container project that spun up a &quot;hello world&quot; golang app. I was able to get the CI/CD pipeline set up that would build the container, push it to the self hosted gitlab container registry, and deploy it to a running Linode server.
My next step is to docker compose the golang container with nginx and certbot. If I ssh into the server and clone the repository, it runs. Now I am trying to deploy the compose to a Linode server. That is where I am currently at the posting of the question(s).</p>
<p>(1) One way would be to use ssh in the pipeline to &quot;git pull&quot; and build/up the compose file just like I did running locally on the remote docker host.</p>
<p>(2) After trying to do some research on the subject, I ran across something about &quot;docker context&quot;. It looks like I could point my runner running the pipeline to point the remote docker host, and then the build/up command would be working on that server. I started a &quot;hello world&quot; pipeline to test that idea, but now I &quot;think&quot; I am fighting a CI/CD issue. Just to test the syntax of the command, I copied/pasted it into the command line on the remote server, I know it needs to be ran on the runner it was just an easy place to test the syntax, it does not throw an error. This is a protected branch and is therefore feels like it needs to mask part of the command. Is that my problem?</p>
<p>So my docker context command is</p>
<pre><code>testcontext-job:
  stage: testcontext
  image: docker:latest
  script:
    - docker context ls
    - export DOCKER_HOST
    - docker context create remote ‐‐docker host=ssh://xxxdeployer@testxxx.xxxxxdev.org
    - docker context ls
</code></pre>
<p><a href="https://i.sstatic.net/Wi2CYAew.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Wi2CYAew.png" alt="Output of the job." /></a></p>
<p>I tried to narrow down the questions, hoping to give context to better questions. If option 1 is an accepted practice, I will not waste more time chasing the &quot;docker context&quot; rabbit.</p>
<p>Maybe I need to look at a 3rd option. :-)</p>

CC BY-SA 4.0
2024-08-08T07:16:45.230Z
Welcome to DevOps! Can you try using another context name instead of "remote"?? Something like "my-remote"??
Ajay
<docker-compose><gitlab><continuous-deployment><cicd>
how to deploy a docker compose project in gitlab CI/CD
Paul
# how to deploy a docker compose project in gitlab CI/CD

(Asked by: username_0 on 2024-08-07)

New to the Devop world so my terminology may be limited or incorrect. I have a self-hosted gitlab server. I had a "hello world" container project that spun up a "hello world" golang app. I was able to get the CI/CD pipeline set up that would build the container, push it to the self hosted gitlab container registry, and deploy it to a running Linode server.
My next step is to docker compose the golang container with nginx and certbot. If I ssh into the server and clone the repository, it runs. Now I am trying to deploy the compose to a Linode server. That is where I am currently at the posting of the question(s).
(1) One way would be to use ssh in the pipeline to "git pull" and build/up the compose file just like I did running locally on the remote docker host.
(2) After trying to do some research on the subject, I ran across something about "docker context". It looks like I could point my runner running the pipeline to point the remote docker host, and then the build/up command would be working on that server. I started a "hello world" pipeline to test that idea, but now I "think" I am fighting a CI/CD issue. Just to test the syntax of the command, I copied/pasted it into the command line on the remote server, I know it needs to be ran on the runner it was just an easy place to test the syntax, it does not throw an error. This is a protected branch and is therefore feels like it needs to mask part of the command. Is that my problem?
So my docker context command is
testcontext-job:
  stage: testcontext
  image: docker:latest
  script:
    - docker context ls
    - export DOCKER_HOST
    - docker context create remote ‐‐docker host=ssh://xxxdeployer@testxxx.xxxxxdev.org
    - docker context ls


I tried to narrow down the questions, hoping to give context to better questions. If option 1 is an accepted practice, I will not waste more time chasing the "docker context" rabbit.
Maybe I need to look at a 3rd option. :-)

**Tags:** docker-compose, gitlab, continuous-deployment, cicd

> **Comments:**
> **username_1**: Welcome to DevOps! Can you try using another context name instead of "remote"?? Something like "my-remote"??  

---

## 1 answers

### Answer by username_2 on 2024-08-17. Score: 1

Approach 1: SSH and Remote Docker Commands
This approach involves SSHing into your Linode server and manually running git pull and docker-compose up commands. This is a straightforward method but can be cumbersome to automate and manage.
deploy:
  stage: deploy
  script:
    - ssh deployer@xxx.xxxxx.dev "cd /path/to/your/project && git pull && docker-compose up -d"

Approach 2: Docker Context
Using Docker Context allows you to manage Docker endpoints easily and execute commands on remote Docker hosts without manually SSHing into them
testcontext-job:
  stage: testcontext
  image: docker:latest
  script:
    - docker context create remote --docker "host=ssh://deployer@xxx.xxxxx.dev"
    - docker context use remote
    - docker context ls

deploy:
  stage: deploy
  image: docker:latest
  script:
    - docker context use remote
    - docker-compose up -d

Be careful
Don't forget the quotations in your docker create context comment.


---

