Unable to Connect to my Docker Container

Hello,
I am very new to Docker so I apologize if this is somewhat an obvious issue to resolve. I am trying to create a Docker container for an R Shiny app
This is my Docker file I use to build my image:

FROM --platform=linux/amd64 bioconductor/bioconductor_docker:RELEASE_3_19-R-4.4.1

RUN R -e "BiocManager::install(c('ComplexHeatmap','GenomicRanges','GenomeInfoDb','IRanges','rhdf5','Rsamtools','S4Vectors','slingshot','SingleCellExperiment'),update=FALSE)"

RUN R -e "install.packages(pkgs=c('shiny','tidyverse','shinydashboard','xgboost','DT','plotly','tidymodels','ggridges','tidytext','bibtex','bslib','circlize','colourpicker','data.table','DBI','DT','fs','ggdendro','ggforce','ggplot2','ggrepel','ggridges','gridExtra','htmltools','jsonlite','Matrix','magrittr','plotly','RColorBrewer','RefManageR','RSQLite','scales','scrypt','Seurat','SeuratObject','shinyhelper','shinymanager','sortable','xml2','grDevices','grid','methods','patchwork','stats','tools','xfun','utils','svDialogs','shinyalert'), repos='https://cran.rstudio.com/')" 

RUN mkdir /root/app

COPY R /root/shiny_save

EXPOSE 3838

CMD ["R", "-e", "shiny::runApp('/root/shiny_save', host='0.0.0.0', port=3838)"]

I build my Docker image using the following line:
docker build -t ufc-app .

I, then, run my Docker using the line:
docker run -d --rm -p 3838:3838 ufc-app

Using Docker Desktop, I get the following output:

2025-04-04 09:35:31 
2025-04-04 09:35:31 R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2025-04-04 09:35:31 Copyright (C) 2024 The R Foundation for Statistical Computing
2025-04-04 09:35:31 Platform: x86_64-pc-linux-gnu
2025-04-04 09:35:31 
2025-04-04 09:35:31 R is free software and comes with ABSOLUTELY NO WARRANTY.
2025-04-04 09:35:31 You are welcome to redistribute it under certain conditions.
2025-04-04 09:35:31 Type 'license()' or 'licence()' for distribution details.
2025-04-04 09:35:31 
2025-04-04 09:35:31   Natural language support but running in an English locale
2025-04-04 09:35:31 
2025-04-04 09:35:31 R is a collaborative project with many contributors.
2025-04-04 09:35:31 Type 'contributors()' for more information and
2025-04-04 09:35:31 'citation()' on how to cite R or R packages in publications.
2025-04-04 09:35:31 
2025-04-04 09:35:31 Type 'demo()' for some demos, 'help()' for on-line help, or
2025-04-04 09:35:31 'help.start()' for an HTML browser interface to help.
2025-04-04 09:35:31 Type 'q()' to quit R.
2025-04-04 09:35:31 
2025-04-04 09:35:32 > shiny::runApp('/root/shiny_save', host='0.0.0.0', port=3838)
2025-04-04 09:35:32 Loading required package: shiny
2025-04-04 09:35:52 
2025-04-04 09:35:52 Listening on http://0.0.0.0:3838

When I try to access http://0.0.0.0:3838 using a browser, I get the error: " This site can’t be reached. The webpage at http://0.0.0.0:3838/ might be temporarily down or it may have moved permanently to a new web address."

I am very new to Docker and I am unsure if I am messing something with my Docker set up or if this is potentially a Firewall issue? I would appreciate any assistance here.

0.0.0.0 only means that it is listening on all available IP addresses. You still need to use a real IP address from a web browser. It could also be “localhost” or 127.0.0.1 or the IP of your host machine. Not because the process is listening on all IP addresses, as it is inside the container, but because your port forwarding rule in the docker run command didn’t specify the IP address so it is also listening on all IP addresses

You run containers, not Dockers: You run containers, not dockers - Discussing Docker variants, components and versioning - DEV Community

Hi Ákos Takács, Thank you so much for the clarification about containers and dockers. I tried using “localhost”, 127.0.0.1 and the IPv4 address of my device when trying to connect from my browser (I assumed I can keep the 0.0.0.0 port in the actual dockerfile). This time, the error I get is: 127.0.0.1 didn’t send any data. ERR_EMPTY_RESPONSE. Should I set the port to be something other than 3838 perhaps or is there another IP I can try listening at? I appreciate any assistance you could provide me with.

Just to be clear: listening on 0.0.0.0 in the Dockerfile (more precisely: the container that is created based on the image created using the Dockerfile).

Running it with this command docker run -d --rm -p 3838:3838 ufc-app (assuming ufc-app is the tag of the image you created) should be reachable on your host os using either localhost:3838 or <host-ip>:3838, or <hostname>:3838.

You can test from inside the container whether the application generally works:

docker run -d --rm --name ufc -p 3838:3838 ufc-app
docker exec -ti ufc curl http://localhost:3838

Hello Metin Y. Thank you so much for your suggestion and explanation. When I try running the two commands you suggested I get the following:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\a_dao> docker run -d --rm --name ufc -p 3838:3838 ufc-app
8d0b02ae73a28cdae2553fd00a480659e6b863fc209d9f4ce45168f1885321aa
PS C:\Users\a_dao> docker exec -ti ufc curl http://localhost:3838
curl: (7) Failed to connect to localhost port 3838 after 0 ms: Connection refused
PS C:\Users\a_dao>

I get the same output when I run these commands from R or from within Docker Desktop. Any ideas why I am running into this error? I appreciate any assistance.

Yup: your application is not running correct, otherwise the curl request from inside the container would have succeeded.

You need to fix the application you containerized. Are you sure the logs don’t indicate any errors?