From d970885afc277d9015604082898e81553444ace2 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Thu, 10 Apr 2025 00:45:38 -0400 Subject: [PATCH] make Docker tutorial applicable to local development Just as likely(?) that someone would be doing the Docker setup on a local machine, not all on a server. --- content/deploy/tutorials/docker.md | 31 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/content/deploy/tutorials/docker.md b/content/deploy/tutorials/docker.md index 0758a6763..3088022ba 100644 --- a/content/deploy/tutorials/docker.md +++ b/content/deploy/tutorials/docker.md @@ -16,21 +16,12 @@ Wherever you decide to deploy your app, you will first need to containerize it. ## Prerequisites -1. [Install Docker Engine](#install-docker-engine) +1. [Install Docker](#install-docker) 2. [Check network port accessibility](#check-network-port-accessibility) -### Install Docker Engine +### Install Docker -If you haven't already done so, install [Docker](https://docs.docker.com/engine/install/#server) on your server. Docker provides `.deb` and `.rpm` packages from many Linux distributions, including: - -- [Debian](https://docs.docker.com/engine/install/debian/) -- [Ubuntu](https://docs.docker.com/engine/install/ubuntu/) - -Verify that Docker Engine is installed correctly by running the `hello-world` Docker image: - -```bash -sudo docker run hello-world -``` +If you haven't already done so, [install Docker](https://docs.docker.com/get-started/get-docker/) on your desktop/server. @@ -38,6 +29,12 @@ Follow Docker's official [post-installation steps for Linux](https://docs.docker +Verify that Docker Engine is installed correctly by running the `hello-world` Docker image: + +```bash +docker run hello-world +``` + ### Check network port accessibility As you and your users are behind your corporate VPN, you need to make sure all of you can access a certain network port. Let's say port `8501`, as it is the default port used by Streamlit. Contact your IT team and request access to port `8501` for you and your users. @@ -183,13 +180,13 @@ Let’s walk through each line of the Dockerfile : b. If your code is in a private repo, please read [Using SSH to access private data in builds](https://docs.docker.com/develop/develop-images/build_enhancements/#using-ssh-to-access-private-data-in-builds) and modify the Dockerfile accordingly -- to install an SSH client, download the public key for [github.com](https://github.com), and clone your private repo. If you use an alternative VCS such as GitLab or Bitbucket, please consult the documentation for that VCS on how to copy your code to the `WORKDIR` of the Dockerfile. - c. If your code lives in the same directory as the Dockerfile, copy all your app files from your server into the container, including `streamlit_app.py`, `requirements.txt`, etc, by replacing the `git clone` line with: + c. If your code lives in the same directory as the Dockerfile, copy all your app files into the container, including `streamlit_app.py`, `requirements.txt`, etc, by replacing the `git clone` line with: ```docker COPY . . ``` - More generally, the idea is copy your app code from wherever it may live on your server into the container. If the code is not in the same directory as the Dockerfile, modify the above command to include the path to the code. + More generally, the idea is copy your app code from wherever it may live on your filesystem into the container. If the code is not in the same directory as the Dockerfile, modify the above command to include the path to the code. 5. Install your app’s [Python dependencies](/deploy/streamlit-community-cloud/deploy-your-app/app-dependencies#add-python-dependencies) from the cloned `requirements.txt` in the container: @@ -217,7 +214,7 @@ Let’s walk through each line of the Dockerfile : ## Build a Docker image -The [`docker build`](https://docs.docker.com/engine/reference/commandline/build/) command builds an image from a `Dockerfile` . Run the following command from the `app/` directory on your server to build the image: +The [`docker build`](https://docs.docker.com/engine/reference/commandline/build/) command builds an image from a `Dockerfile` . Run the following command from the `app/` directory to build the image: ```docker docker build -t streamlit . @@ -244,7 +241,7 @@ Now that you have built the image, you can run the container by executing: docker run -p 8501:8501 streamlit ``` -The `-p` flag publishes the container’s port 8501 to your server’s 8501 port. +The `-p` flag publishes the container’s port 8501 to your host machine’s 8501 port. If all went well, you should see an output similar to the following: @@ -260,6 +257,6 @@ To view your app, users can browse to `http://0.0.0.0:8501` or `http://localhost -Based on your server's network configuration, you could map to port 80/443 so that users can view your app using the server IP or hostname. For example: `http://your-server-ip:80` or `http://your-hostname:443`. +**On a server:** Based on your network configuration, you could map to port 80/443 so that users can view your app using the server IP or hostname. For example: `http://your-server-ip:80` or `http://your-hostname:443`.