Skip to content

How to build and use a Docker image for Deep Learning development.

Notifications You must be signed in to change notification settings

DataScienceUB/MyDocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyDocker: How to build and use a Docker image for Deep Learning development.

Problemática

  1. If 2 people are working on the same project but with 2 different environments, there may be dependency version issues.
  2. Some packages are optimize for a special OS.

I. What is Docker

Docker is a manager of container.

Container:

container

• Isolates app from each other

• Shares the same kernel – kernel shares resources with the host and interacts with the containers

container

Advantages

• Quicker to launch (no os to boot)

• Portability (less dependencies between processed layers)

• Efficiency

container

II. Run a container

  1. Pull an image from Docker hub: docker login then docker pull

  2. Check the image: docker images

  3. Create a container: docker run –it nom Few options:

    INSTRUCTION SIGNIFICATION
    -i Interactive mode
    -p Publish a container᾿s port or a range of ports to the host format (-p 8888:4000)
    -t Allocate a pseudo-tty
    -v path/to/volume Bind mount a volume
  4. Stop the container: docker stop id_container nom

  5. Interact with a container with shell: docker run –it nom_container /bin/bash

  6. Save the container after modification: docker commit id_container nom

  7. Stop the container

  8. Confirm the container has been stop: docker ps –a

  9. Delete the container: docker rm id_container

III. Build your own container

  1. Create a directory
  2. Create your Dockerfile

Commands:

INSTRUCTION SIGNIFICATION
FROM Set base image
LABEL Add metadata
COPY Copy files/directories into the image
ENV Set environment variable
EXPOSE Informs Docker that the container listens on the specified network ports at runtime
WORKDIR Set working directory
RUN Execute shell commands in a new layer
ENTRYPOINT Configure container to run as executable
CMD Provide default for executing container

Example

container
  1. Create hello_world.py: print("Hello world!")
  2. Build your image: docker build –t nom .
  3. Create the container: docker run nom
  4. Upload to docker hub:
    • docker login
    • docker tag image username/repository:tag (example: docker tag friendlyhello john/first_docker:test)
    • docker push username/repository:tag

IV. Exercise

  1. Create a directory

  2. Create your Dockerfile in this new directory.

    FROM ubuntu:latest

    RUN apt-get update && apt-get install -y python3 python3-pip

    COPY requirements.txt .

    RUN pip3 install jupyter

    RUN pip3 install -r requirements.txt

    RUN useradd -ms /bin/bash jupyter

    USER jupyter

    WORKDIR /home/jupyter

    COPY hello_world.txt .

    ENTRYPOINT ["jupyter", "notebook", "--ip=*"]

  3. Create requirements.txt with Tensorflow, Keras.

  4. Create hello_world.txt

  5. Build your image: docker build -t jupyter .

  6. Create a new container: docker run -it -p 8888:8888 jupyter /home

  7. Consulte the results on your browser (you might need to change your ip address)

About

How to build and use a Docker image for Deep Learning development.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages