I use docker-compose to build a PHP 8 / Nginx for a Laravel application. I start it successfully with docker-compse -up.
docker ps
gives me the following output:
CONTAINER ID IMAGE COMMAND NAMES
b0e55ad98a63 laravel-app "docker-php-entrypoi..." laravel_docker_medium_tut_app_1
da779e8fa633 nginx:alpine "/docker-entrypoint...." laravel_docker_medium_tut_nginx_1
My folder where I have the docker-compose.yml is called: ./laravel_docker_medium_tut/.
I can rename the containers with:
docker rename b0e55ad98a63 laravel-api-app
docker rename da779e8fa633 laravel-api-nginx
docker ps now prints me the successfully renamed containers:
CONTAINER ID IMAGE COMMAND NAMES
b0e55ad98a63 laravel-app "docker-php-entrypoi..." laravel-api-app
da779e8fa633 nginx:alpine "/docker-entrypoint...." laravel-api-nginx
Problem:
If I now run docker-compose down
and then docker-compose up -d
again I have the old names again: laravel_docker_medium_tut_app_1, laravel_docker_medium_tut_nginx_1 .
My question: How can I permanently rename the names?
Here is my docker-compose.yml:
version: "3.7"
services:
#Laravel App
app:
build:
args:
user: mike
uid: 1000
context: ./
dockerfile: Dockerfile
image: laravel-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- mynetwork
#Nginx Service
nginx:
image: nginx:alpine
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./nginx/conf.d:/etc/nginx/conf.d/
networks:
- mynetwork
#Mysl Service
networks:
mynetwork:
driver: bridge
Thanks for your time and help!
CodePudding user response:
You can use container_name
in your docker-compose.yaml
.