0

I have an nginx config file with a line such as:

location / {
    proxy_pass http://my-container:1234;
}

Problem is, this changes over time, depending on which machine, to things like:

my-container-my-container-1
my-container_my-container-1
my-container-my-container_1

How do I keep docker container names consistent when working with docker-compose.yml files?

docker-compose.yml:

version: '3.7'

services:
    nginx:
        image: nginx:stable-alpine
        volumes:
            - ./nginx.conf:/etc/nginx/nginx.conf
        ports:
            - 80:80
        restart: always
        depends_on:
            - my-container
    my-container:
        build: .
        expose:
            - 1234

nyxusaha
  • 49
  • 6
  • 1
    Regardless of how compose or swarm names the container, the service name and network alias is `my-container`. What is the error you are trying to solve, and can you provide a [mcve]? – BMitch Mar 29 '23 at 15:27
  • 1
    Does this answer your question? [docker-compose.yml container\_name and hostname](https://stackoverflow.com/questions/55522620/docker-compose-yml-container-name-and-hostname) – ItayB Mar 30 '23 at 05:50

0 Answers0