Environment maintenance made with Docker (I want to post-process GrADS in Python

What do you want to do?

--I want to read a file for GrADS with Python and post-process it. ――But the environment of shared computational resources must be clean ――However, there are many things you want to install, such as conversion software and libraries.

So let's use container virtualization.

Docker What is good with Docker is that you can create a dedicated virtual computer that performs the necessary post-processing without polluting the computational resources. You can launch the container when you use it, discard it after processing it, and launch it again when needed. In the case of Docker, the start-up cost is very low, so you can easily start it up, perform one process, and then discard it again.

Environmental maintenance procedure

It would be nice to write a Dockerfile for automation, but for now I'll just launch and maintain the shell and simply commit it to create the image. If you want to use it for a long time, you should create a Dockerfile so that it can be upgraded, but it is better to check the basic functions first in the shell.

This time, based on Ubuntu, install cdo, pip3, and netcdf4.

1. Pull (pick up) the original image and run it

This time I will use Ubuntu.

$ docker pull ubuntu/ubuntu
$ docker images

You can confirm that the image has been created.

To run the image

$ docker run -it ubuntu/ubuntu

will do.

2. Installation of required software

Install pip3 and cdo. Also install netCDF4 with pip3.

# apt update
# apt install python3 python3-pip cdo
# pip3 install netCDF4

3. Operation check

Check if it can be converted properly with cdo and netCDF4 can also be imported.

# python3
>>> import netCDF4 as nc
>>> ^D
# cdo
....

4. Commit to create an image

Use the exit command or Ctrl + d to exit and create an image. The container ID required to create the image requires -a to confirm the finished container.

# exit
(host) $ docker ps -a

I think the screen will look like this. CONTAINER ID will be the container ID specified at the time of commit. There is an image name in IMAGE, and exited ** ago in STATUS, so you can see which one is roughly there. image.png

$ docker commit [container id] [author]/[image name]

Let's commit like that.

$ docker images

You can confirm that the image has been created.

5. Let me actually calculate

There are two ways to actually calculate, you can also run and then interactively run from the shell. However, this time I will specify a command at the time of run and execute it.

By binding the directory of programs and data groups to Docker, you can actually access it easily from the container. Also, do X forwarding to check the graph.

$ sudo docker run -e DISPLAY=$DISPLAY --net host -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/root/.Xauthority -v /home/xxx/:/home/ --shm-size 16g xxx/ubuntu-cdo2 /bin/bash -c "cd /home/speedy-epyc/speedy/python-script; python3 rmse.py"

Add --shm-size if necessary if there is a missing program.

Recommended Posts

Environment maintenance made with Docker (I want to post-process GrADS in Python
I want to work with a robot in python.
I want to debug with Python
I want to build a Python environment
I want to analyze logs with Python
I want to play with aws with python
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
I want to run Rails with rails s even in vagrant environment
I want to use MATLAB feval with python
I wanted to use jupyter notebook with docker in pip environment (opticspy)
I want to create a window in Python
I want to make a game with Python
I set the environment variable with Docker and displayed it in Python
I want to merge nested dicts in Python
I want to use Temporary Directory with Python2
#Unresolved I want to compile gobject-introspection with Python3
I want to solve APG4b with Python (Chapter 2)
I want to write to a file with Python
I want to display the progress in Python!
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to write in Python! (1) Code format check
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to transition with a button in flask
I want to handle optimization with python and cplex
I want to write in Python! (2) Let's write a test
Even in JavaScript, I want to see Python `range ()`!
I made a Python3 environment on Ubuntu with direnv.
I want to randomly sample a file in Python
I was addicted to scraping with Selenium (+ Python) in 2020
I want to inherit to the back with python dataclass
I want to write in Python! (3) Utilize the mock
I want to AWS Lambda with Python on Mac!
[ML Ops] I want to do multi-project with Python
I want to use the R dataset in python
I want to run a quantum computer with Python
I want to do something in Python when I finish
I want to manipulate strings in Kotlin like Python!
I made blackjack with python!
Prepare python3 environment with Docker
I made blackjack with Python.
I made wordcloud with Python.
I want to be able to analyze data with Python (Part 3)
I made a simple typing game with tkinter in Python
I want to be able to analyze data with Python (Part 1)
I made a package to filter time series with python
I want to do something like sort uniq in Python
I want to be able to analyze data with Python (Part 4)
I want to be able to analyze data with Python (Part 2)
I want to automatically attend online classes with Python + Selenium!
[Python] I want to use the -h option with argparse
I want to use a virtual environment with jupyter notebook!
I made a puzzle game (like) with Tkinter in Python
I want to be able to run Python in VS Code
I want to make input () a nice complement in python
Build Mysql + Python environment with docker
I want to set up a GUI development environment with Python or Golang on Mac
Numer0n with items made in Python
I made a class to get the analysis result by MeCab in ndarray with python
I made a fortune with Python.
I made a program to collect images in tweets that I liked on twitter with Python