The run file

Now, we've got a Dockerfile ready to go. Let's create the build script that will build this container and allow us to work inside of this Docker container. Create a folder in the full-gan folder called data. Then, create a file in the full-gan folder called run.sh. A .sh file is a shell script and will allow us to run a series of commands, as if we are running from the Terminal. Open the run.sh script and type the following commands:

#/bin/bash
nvidia-docker build -t ch3 .

As in Chapter 2Data First – Easy Environment and Data Prep, /bin/bash tells the interpreter to use the bash interpreter for this script. The NVIDIA-Docker container command allows us to build the image with the tag ch3 and uses the Dockerfile in the current directory because of the dot at the end of the command. Next, let's make sure that any Windows OS we want to pass through the container can get through by issuing the following command:

xhost +

This tells xhost to grant the appropriate privileges to the Docker container to allow Windows OS to pass through and appear in our xhost (the Window Manager) on our Ubuntu machine. Finally, let's see what the docker command does to run this container:

docker run -it 
--runtime=nvidia
--rm
-e DISPLAY=$DISPLAY
-v /tmp/.X11-unix:/tmp/.X11-unix
-v $HOME/full-gan/data:/data
ch3 /bin/bash # python3 train.py

Here's the breakdown for each one of these commands, with a comment next to each line:

  • docker run -it : This flag allows the container to run in interactive mode.
  • --runtime=nvidia : This means use the NVIDIA runtime so that we have access to the graphics card.
  • --rm : This flag tells the Docker system to discard any changes to the image after exit.
  • -e DISPLAY=$DISPLAY : This is a variable to allow the Window OS to pass through the container.
  • -v /tmp/.X11-unix:/tmp/.X11-unix : This allows the Windows OS to pass through the container.
  • -v $HOME/full-gan/data:/data : This maps a folder at the root directory to your data folder.
  • ch3 /bin/bash: End of ch3: python3 train.py .For now, /bin/bash opens a bash Terminal.

Now, click Save and let's check to make sure that we have the appropriate directory structure with our files:

full-gan/
├── Dockerfile
└── run.sh

One last thing before we finish this chapter—make sure to make the shell script executable so that we can use it throughout this chapter:

chmod 775 run.sh

Go ahead and run it so that you can ensure that it properly builds the Dockerfile and allows you to get an interactive shell:

sudo ./run.sh

This should do it! Make sure you can access Python3 and Keras. Then, go to the next recipe!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.235.8