-
Notifications
You must be signed in to change notification settings - Fork 0
Expose Kitura's Port in Docker Container to Host Machine
Depending on your Docker installation the instructions to expose the Docker container's port differs:
These are the steps to expose Kitura's port in a Docker container to the host (e.g. an OS X laptop):
-
Execute
docker run -d -P ibmcom/swift-ubuntu:latest
. -
Execute
docker ps
. -
Inspect the values under the PORTS column for the container you just started. You should see something like the following:
0.0.0.0:32768->8090/tcp
. This means that Kitura’s port8090
in the Docker container is mapped to port32768
on the host. Now, the host in this case is not the OS X laptop. Instead, it is the Virtual Box machine that Docker uses. -
Go to Virtual Box, and open the settings panel for the virtual machine that is running Docker (i.e. right click on the virtual machine and select
Settings
). -
Go to the Network tab and click on
Port Forwarding
. -
Add a new row with the following values:
- name: kitura
- protocol: tcp
- host ip: 127.0.0.1
- host port: 8090
- guest port: <the host port reported under the PORTS column (e.g. 32768)>
-
Click
OK
andOK
again to save the settings for the virtual machine. -
Open your browser and go to
http://localhost:8090
. You should see the Kitura welcome page.
Since the new Docker for Mac macOS app removed the need for VirtualBox, exposing your Kitura server's port in a Docker container is much simpler. Simply pass in the port binding as an option when you first run the container image, like so:
docker run -p <host-port>:<container-port> [additional-options] ibmcom/swift-ubuntu:latest
.
For example, if your Kitura server is running on port 3000, and you want to make it accessible at port 4000 on the host OS:
docker run -p 4000:3000 ibmcom/swift-ubuntu:latest
Your Kitura server can now listen on port 3000 inside the Docker container, and be accessible through your host OS at port 4000. Please check the official docs for more information on how to configuration the -p
option.
NOTE This only works if you don't have a live container already. There is no way to expose ports on a live container. If you already have a live container and wish to expose a port, you can first commit the live container to a new image, then run this new image with the -p
option.