hemberg-lab / scRNA.seq.course

Analysis of single cell RNA-seq data course
https://www.singlecellcourse.org
GNU General Public License v3.0
670 stars 360 forks source link

Can I change the docker image port ? #181

Closed huang-sh closed 2 years ago

huang-sh commented 2 years ago

Hi, thank you for providing the wonderful scRNA-Seq learning resource.

I am using the course docker image. I can run the docker image with

$ docker run  -p 8888:8888 -e PASSWORD="jupyter" quay.io/cellgeni/scrna-seq-course:v5.14

But when I use the other port, it still work on port 8888:

$ docker run -p 8889:8889 -e PASSWORD="jupyter" quay.io/cellgeni/scrna-seq-course:v5.14

                                ...........
    To access the server, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/jpserver-8-open.html
    Or copy and paste one of these URLs:
        http://a28e24e73171:8888/lab?token=3dbe183d32ce79da227caa473d796b329c47347dba69371d
     or http://127.0.0.1:8888/lab?token=3dbe183d32ce79da227caa473d796b329c47347dba69371d

I am not familiar with docker. Can I run multiple containers with different ports ?

prete commented 2 years ago

Hi @huang-sh the port of the container will remain 8888, if you want to match it to a different port on the host machine you only need to change only the first port like so:

docker run -p 8889:8888 -e PASSWORD="jupyter" quay.io/cellgeni/scrna-seq-course:v5.14

You can read more on port publishing/exposing on the Docker docs: https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose

huang-sh commented 2 years ago

Thank you! That is I want.
I am confused that it still show the port 8888 when I run docker run -p 8889:8888 -e PASSWORD="jupyter" quay.io/cellgeni/scrna-seq-course:v5.14. Anyway, I can access the server with "http://127.0.0.1:8889/lab" now.

$ docker run -p 8889:8888 -e PASSWORD="jupyter" quay.io/cellgeni/scrna-seq-course:v5.14
                                    .........
    To access the server, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/jpserver-7-open.html
    Or copy and paste one of these URLs:
        http://4dcea16fdc40:8888/lab?token=094efe8f0bdd28438bcd5a8923d2ce3cd60b8553b6a0550b
     or http://127.0.0.1:8888/lab?token=094efe8f0bdd28438bcd5a8923d2ce3cd60b8553b6a0550b
prete commented 2 years ago

I'm glad you can access the server now @huang-sh. What you see in the terminal is running inside the container and —as far as Docker is concern— that's still running on port 8888 of the container.

What you're doing with the -p 8889:8888 is mapping that container port (8888) to a port on your host machine (8889) that's accesible for you. That means when you try to access localhost:8889 that will be routed internally by Docker to the running container's port 8888.

Should you want to know more about port binding you can read this, this or this.