I am trying to get a container built that has ports forwarded, such that code running in the container can access a remote db for instance. So I put the line
CMD ssh -L 27017:localhost:27017
in my dockerfile and then run it, but in no case do I see ports forwarded (I tried RUN instead of cmd, and tried both interactively running the container or using -d , but in the former case I don't have forwarding and in the latter case the container exits soon after starting, even after tacking && /bin/bash to the end of the ssh command). The only way I have succeeded doing this is doing an interactive run
$docker run -it --name cont_name im_name /bin/bash
and then from the interactive shell doing the ssh necessary for port forwarding (which now ties up the shell). Then from another window on my local host, I 'get inside' the first container using
$ docker exec -it cont_name bash
where I now indeed see ports forwarded . Is there a better/automatic way to do this? 'screen' seems to be a hassle to get running in a container.