Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run docker image with specific version and port forwarding

Tags:

docker

I want to run official Cassandra version 2.1.9 inside docker. Also, I want to have following ports mapping:

7000:7000  
7001:7001  
7199:7199  
9042:9042  
9160:9160  

What command do I have to run in order to achieve this goal?

like image 243
gandra404 Avatar asked Oct 07 '16 13:10

gandra404


People also ask

How do I run Docker on port 8080?

The format of the --publish command is [host port]:[container port] . So, if we wanted to expose port 8000 inside the container to port 8080 outside the container, we would pass 8080:8000 to the --publish flag. Start the container and expose port 8080 to port 8080 on the host.

How do I map a container port to a host port?

To make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.

Can we expose a port on running container?

You cannot do this via Docker, but you can access the container's un-exposed port from the host machine.


1 Answers

The official Cassandra image doesn't have 2.1.9. The closest is 2.1.15 which shouldn't have any compatibility issues. The easiest way to run it is:

docker run -d -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9042:9042 -p 9160:9160 cassandra:2.1.15

-p publishes a ports from the image to a specific port number on the host. The Cassandra Dockerfile exposes exactly those ports. You'd probably want to give the container a --name as well.

If you really want 2.1.9 you'll have to hunt for a non-official image or build your own.

like image 155
Elton Stoneman Avatar answered Oct 17 '22 05:10

Elton Stoneman