How to change port of docker container on Ubuntu 18.04 LTS

  • Find the hash of the container with “docker ps -a”
  • Stop the docker container with “docker stop”
  • Next you have to stop docker all together with “sudo systemctl stop docker.service” and also “sudo systemctl stop docker.socket”
  • Then you cd to /var/lib/docker/containers/<hash_of_container>
  • Now open with your favorite text editor hostconfig.json
  • Look for “HostPort”:”<port_you_want>”
docker ps -a docker stop container_name sudo systemctl stop docker.service sudo systemctl stop docker.socket #you may have to be root cd /var/lib/docker/containers/hash_of_container #I like nano nano hostconfig.json #"HostPort":"<port_you_want>"
Code language: PHP (php)

Leave a comment

Your email address will not be published. Required fields are marked *