- 
                Notifications
    
You must be signed in to change notification settings  - Fork 614
 
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
      
      
            afeld
  wants to merge
  1
  commit into
  streamlit:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
afeld:patch-2
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -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/) | ||
| 
     | 
||
| 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 | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Took out the   | 
||
| ``` | ||
| 
     | 
||
| ### 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 | |
| 
     | 
||
| <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> | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
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.