Docker-compose: change exposed port?


I want to install the following image:

My Question is now how can i change the exposed ports that are given in DockerFile?

Here is the document about that, but nothing about changing ports:

Thanks in advance.

You usually don’t need to do that; instead, you need to change the ports that Docker publishes. In this case the application provides its own Docker Compose setup, and you need to change the one “ports” line in the YAML file to map the container’s port 80 to some other port on the host.

(The broader answer is to edit the Dockerfile, change the port number on its EXPOSE line, and also do application-specific setup to cause it to listen on a different port. But since docker run -p can pick a port of your choice to make the service visible externally, this isn’t usually necessary. My application setup has a handful of HTTP-based services that all EXPOSE 80 because that’s the natural port for HTTP, and those get remapped to different port numbers at launch time.)


Thanks for your reply, as now i understand (sorry for my bad english):

What if a new images is avaible (docker-compose pull) then my settings get overrides?


  • If the container is running how can i enter them and edit files and restart systems? (bash)

Thanks in advance.

Right. If you’ve already started the setup, you need to stop, remove, and restart the one container.

docker-compose pull only updates the images (the things referred to by the various image: lines) but not the docker-compose.yml itself. If you got the file from a git checkout, you could need to merge your local changes when you git pull. (But it’s just a file at this level.)

Usually you don’t need to. Standard Docker practice is to put only one service in a container, so if you need to restart a single service, just restart that container.

Also remember that it is extremely routine to stop, delete, and restart containers, and when you do that, their local filesystem is gone.

With those two caveats, docker exec is a debugging tool that can get you a shell inside a running container. (It’s not intended to be part of your core workflow.)

1 Like