The only 2 ways I know of to map X port from my host machine to Y port on a Docker container is to use docker run -p X:Y
or docker-compose.yaml
. An existing workflow at my company uses the following to create, start, and connect to a devcontainer:
docker create ...
docker start ...
docker exec -it ...
I would now like to add SSH connectivity to the container, but know of no way to map an arbitrary local port to 22 in the container using any of the existing steps (create
, start
, exec
). Is this possible with the existing workflow? Is there some technical difficulty behind the decision not to be able to map ports with docker create
?
P.S. The third way I know of to map ports is to stop the container, stop the Docker service, edit the container's hostconfig.json
, and restart the Docker service and container -- but I'm not going to do that in our workflow.