Search code examples
dockergitlabdocker-composegitlab-omnibus

Translate docker run command to docker compose


I'm losing my mind a little here, I think I've translated the command correctly, but I'm getting an error when I try docker-compose up -d

Here's my command, this works - without failure:

sudo docker run -i \
    --hostname localhost \
    --publish 444:443 --publish 8080:8080 --publish 23:22 \
    --name gitlab \
    --restart always \
    --volume /home/admin/gitlab/config:/etc/gitlab \
    --volume /home/admin/gitlab/logs:/var/log/gitlab \
    --volume /home/admin/gitlab/data:/var/opt/gitlab \
    --volume /home/admin/gitlab/logs/reconfigure:/var/log/gitlab/reconfigure \
    -e VIRTUAL_HOST=git.example.com
    -e VIRTUAL_PORT=8080
gitlab/gitlab-ce:latest

Here's my docker-compose.yml file, which isn't working

gitlab:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  container_name: gitlab
  ports:
    - '8080:80'
    - '23:22'
    - '444:443'
  volumes:
    - '/home/admin/gitlab/config:/etc/gitlab'
    - '/home/admin/gitlab/logs:/var/log/gitlab'
    - '/home/admin/gitlab/data:/var/opt/gitlab'
    - '/home/admin/gitlab/logs/reconfigure:/var/log/gitlab/reconfigure'
  environment:
    - VIRTUAL_HOST=git.example.ca
    - VIRTUAL_PORT=8080

Can you see something that I'm doing wrong?


Solution

  • Add hostname: localhost as you do it in docker run to have

    gitlab:
      image: 'gitlab/gitlab-ce:latest'
      restart: always
      container_name: gitlab
      hostname: localhost
      ports:
        - '8080:80'
        - '23:22'
        - '444:443'
      volumes:
        - '/home/admin/gitlab/config:/etc/gitlab'
        - '/home/admin/gitlab/logs:/var/log/gitlab'
        - '/home/admin/gitlab/data:/var/opt/gitlab'
        - '/home/admin/gitlab/logs/reconfigure:/var/log/gitlab/reconfigure'
      environment:
        - VIRTUAL_HOST=git.example.ca
        - VIRTUAL_PORT=8080