I have a huge problem with docker – after restarting it changes the container mapping port
I start my container:
docker run -i -t -d -p 3000:63000 test
and everything is great, but after restart the inner port (63000) was changed to 8080
my dockerfile:
FROM node:18-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 63000
CMD [ "node", "serverWS.js" ]
Expose is ok. I have no idea what more I can check. Maybe someone can help?
docker.compose.yml
version: '3.9'
services:
php-env:
image: cento_php8
#image: centos_ms
#image: mydemophpimage
#build: .
restart: always
volumes:
- ./app:/var/www/html
- ./php.ini:/etc/php.ini:ro
ports:
- 5000:80
Docker version 24.0.2, build cb74dfc
By restart I mean the machine on which docker is running was turned off and on again. After this, docker starts automatically (settings: restart always) but the container is started on a different port. Im checking it by listing running containers before and after the machine restart. Before I have 0.0.0.0:3000->63000, and after restarting 0.0.0.0:3000->8080
2
Answers
The change in the container’s internal port from 63000 to 8080 could be caused by a conflict with another service or process running on port 63000. When the Docker host machine restarts, it may not be able to allocate port 63000 for the container, resulting in the container being assigned a different available port (in this case, 8080).
To resolve this issue, remove container and try with another port:
You should add the desired port mapping to your
docker-compose.yml
and start the container by usingdocker compose up -d
instead ofdocker run
.