Skip to content

make Docker tutorial applicable to local development #1274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions content/deploy/tutorials/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@ 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/)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official documentation talks about this, with expanded information. Linking there instead.


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.

<Tip>

Follow Docker's official [post-installation steps for Linux](https://docs.docker.com/engine/install/linux-postinstall/) to run Docker as a non-root user, so that you don't have to preface the `docker` command with `sudo`.

</Tip>

Verify that Docker Engine is installed correctly by running the `hello-world` Docker image:

```bash
docker run hello-world
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took out the sudo.

```

### 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.
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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 .
Expand All @@ -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:

Expand All @@ -260,6 +257,6 @@ To view your app, users can browse to `http://0.0.0.0:8501` or `http://localhost

<Note>

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`.

</Note>