skip to Main Content

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

enter image description here

2

Answers


  1. 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:

    docker stop <container_id>
    docker rm <container_id>
    docker run -i -t -d -p 3000:3000 test
    
    Login or Signup to reply.
  2. You should add the desired port mapping to your docker-compose.yml and start the container by using docker compose up -d instead of docker run.

    version: '3.9'
    
    services:
    ... 
        your-service:
            build:
                context: .
                dockerfile: Dockerfile
            restart: always
            ports:
                - 3000:63000
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search