Changing the port of a Cockpit container (docker)

If you launched your cockpit project using docker, you probably used this command:
docker run -d --name cockpit -p 8080:80 agentejo/cockpit

You might want to change the port at which this container is deployed. I looked around for the solution and I did find an answer on Stackoverflow. I think a better solution with exact commands is required though.

  1. Use docker ps to get the first few letters of your container ID
  2. Stop docker using docker service stop
  3. Navigate to /var/lib/docker/containers/your-container-id. You might have to do this as a root user
  4. Open the hostconfig.json file and find the “HostPort” key. Change your port to whatever you want here. Save the file and exit.
  5. Start docker again using docker service start
  6. Use docker ps to check if the port has changed

I hope this helps someone!