Docker: permanently set internal apache port to 8888 instead of 80?

I want to install Nextcloud with docker default configuration (sqlite database) and Apache internal port at 8888, instead of port 80.

When I use the standard docker-compose.yml it doesn’t work. Either Apache does not bind at all or it always binds to port 80.

version: ‘2’

volumes:
nextcloud:

services:
app:
image: nextcloud
restart: always
ports:
- 8888:8888
volumes:
- nextcloud:/var/www/html

Is there a Docker ENV variable where I can permanently set custom Apache port whenever I spinup the image?

I don’t know if this is possible with just the compose file… You could do that with a custom image. But why would you like to do it in the first place? You can bind whatever port you like to the exposed port of the container.

if you really want to do it: search for the vhost conf file where “listen :80” is defined, copy it to your host, change it to “listen :8888” and include this file in your docker-compose volume definition.

but as chartman123 said already: “why you want to do this?”

maybe you get confused with container exposed port and the port you use to access from outside.

most likely you are looking for

  ports:
    - 8888:80

which means the container keeps using default port 80 and you use port 8888 on your docker server to access this container. there is no reason to change the exposed port of the docker container… there is no obligation to have 1:1 relation of the host port and container port. even if you run multiple Nextcloud containers in parallel each container can keep using port 80 on their side - you only need unique port on the host side (or even better expose multiple systems with reverse proxy like traefik and different domains (nc1.mycloud.com, nc2.mycloud.com etc…) on well known port like http or https so you don’t need to add port manually when you access the instance…