Pytorch execution environment with Docker

Introduction

Build a Jupyter Notebook environment that can use Pytorch.

I wanted an environment where Pytorch can be used easily, and I often forget the contents and options of Dockerfile and yml file, so I wrote this article as a reminder.

Create a Docker image

Use jupyter/datascience-notebook as the base image.

This time, in addition to this, install pytorch. Check the pip command here (https://pytorch.org/get-started/locally/). I selected it as shown in the figure below. image.png

Next, create a container image from Dockerfile. Dockerfile looks like this

FROM jupyter/datascience-notebook

USER root

RUN pip install torch torchvision

USER jovyan
WORKDIR /home/jovyan

--Image build (Docker build)

docker build -t Favorite image name.

--Container creation (Docker run)

docker run -p 80:8888 -v ./:/home/jovyan/work image name

--Specify the port with the p option. --Specify a free port on the host side --- p "Container side": "Host side" --v Optional mount the host-side directory. --- v "Host side": "Container side" --Please put the source code in the "host side" directory.

After running docker run, you should see the jupyter notebook at http: // localhost: 8888.

However, as it is, it is troublesome to specify various options every time Docker run, so make it possible to execute parameters at once with docker-compose.

Run with docker-compose

Create docker-compose.yml like this,

version: "3"
services:
  jupyterlab:
    build:
      context: .
    user: root
    ports:
      - "80:8888"
    volumes:
      - "./:/home/jovyan/work"
    environment:
      GRANT_SUDO: "yes"
    command: start-notebook.sh --NotebookApp.token=""

Execute docker-compose up --build to create and start the container.

--You can create a container using Dockerfile with build. --This time it's context: . so I'm using Dockerfile in the current directory --Specify the ports with ports. --"Container side": "Host side" --Specify the directory to mount with volumes --"Host side": "Container side" --Specify the command when starting the container with command --Use start-notebook.sh to start jupyter notebook --If you add the option --NotebookApp.token =" " `, you will not be able to confirm the Token when accessing.

Now you should be able to use the jupyter notebook by accessing http: // localhost: 8888.

After that, let's implement various models with pytorch.

that's all.

Recommended Posts

Pytorch execution environment with Docker
[Docker] Build Jupyter Lab execution environment with Docker
[Docker] Rails 5.2 environment construction with docker
Build docker environment with WSL
React environment construction with Docker
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
Node.js environment construction with Docker Compose
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
Environment construction with Docker for beginners
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
Create SolrCloud verification environment with Docker
Create Laravel environment with Docker (docker-compose)
[Environment construction with Docker] Rails 6 & MySQL 8
Use cuda11.0 with pytorch using Docker
Build docker + laravel environment with laradock
Alert slack with alert manager in Docker environment
GPU environment construction with Docker [October 2020 version]
Rails environment construction with Docker (personal apocalypse)
Building Rails 6 and PostgreSQL environment with Docker
Laravel development environment construction with Docker (Mac)
Build a PureScript development environment with Docker
Create Rails 6 + MySQL environment with Docker compose
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Edit Mysql with commands in Docker environment
Create a MySQL environment with Docker from 0-> 1
Build a WAS execution environment from Docker
Create Spring Boot-gradle-mysql development environment with Docker
[Docker] Create Node.js + express + webpack environment with Docker
Laravel + MySQL + phpMyadmin environment construction with Docker
Build a Wordpress development environment with Docker
Build an environment with Docker on AWS
Docker environment construction
Lightweight PHP 7.4 development environment created with Docker
Build TensorFlow operation check environment with Docker
How to build Rails 6 environment with Docker
Spring Boot environment construction with Docker (January 2021 version)
[Memo] Create a CentOS 8 environment easily with Docker
Make SpringBoot1.5 + Gradle4.4 + Java8 + Docker environment compatible with Java11
Self-hosting with Docker of AuteMuteUs in Windows environment
Build a Laravel / Docker environment with VSCode devcontainer
Environment construction command memo with Docker on AWS
Build a WordPress development environment quickly with Docker
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Prepare a scraping environment with Docker and Java
React + Django + Nginx + MySQL environment construction with Docker
Build mecab (NEologd dictionary) environment with Docker (ubuntu)
[Rails] How to build an environment with Docker
[First team development ②] Build an environment with Docker
Wordpress local environment construction & development procedure with Docker
Create a Spring Boot development environment with docker
Rails Docker environment construction
Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Use Puphpeteer with Docker