# Container Camp, Spring-2021, Day 2 - March 16th
----
## Topic:
**Container Camp Materials/Useful links**
- Course Homepage
- [https://learning.cyverse.org/projects/cyverse-container-camp/en/latest/index.html](https://learning.cyverse.org/projects/cyverse-container-camp/en/lcd atest/index.html)
- Course Schedule
- [https://learning.cyverse.org/projects/cyverse-container-camp/en/latest/getting_started/agenda.html](https://learning.cyverse.org/projects/cyverse-container-camp/en/latest/getting_started/agenda.html)
- [CyVerse Discovery Environment 2: https://de2.cyverse.org](https://de2.cyverse.org)
- [iRODS Command Documentation: https://docs.irods.org/master/icommands/user/](https://docs.irods.org/master/icommands/user/)
- [Classic DE: https://de.cyverse.org/de/](https://de.cyverse.org/de/)
- [Classic DE Tool Integration Walkthrough](https://learning.cyverse.org/projects/cyverse-container-camp/en/latest/cyverse/tool_integration_app_building_DE.html)
- [What are computer ports??](https://www.computerhope.com/jargon/p/port.htm#:~:text=When%20referring%20to%20a%20physical,external%20devices%20such%20as%20printers)
- [Docker Command Reference](https://docs.docker.com/engine/reference/builder/)
- [Docker Cheat Sheet PDF](https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf)
- [Getting back onto Atmosphere to run docker (Day 1 - Amanda's tutorial)](https://learning.cyverse.org/projects/cyverse-container-camp/en/latest/docker/dockerintro.html)
- [The RockerVerse, Containerization for R](https://journal.r-project.org/archive/2020/RJ-2020-007/RJ-2020-007.pdf)
---
### Discussion and Notes:
**General notes:**
**iRODS `irsync`** this command will sync data from a CyVerse data store *folder* `-r` is the recursive flag. `-V` means very verbose and `-K` is the flag for use MD5 checksums to verify data integrity.
`irsync -rVK i:/iplant/home/some/data_store/path /home/rstudio/some/local/path`
`iget` pulls individual files or folders
`iput` puts individual files or folders in the data store
### Docker Run Rocker RStudio Command & an explanation of port syntax
`docker run -it -e PASSWORD=rstudio1 -p 8787:8787 rocker/tidyverse:latest`
At the login page enter `rstudio` for the username and whatever you chose as the argument for `-e PASSWORD=rstudio1`. Access this via a new browser tab and your `atmosphere-ip-address:8787`
*If you are running docker on your local machine...* The container will be running at `http://localhost:8787/`
Computer port syntax is `local-machine-port:container-port`
---
### Writing our own Dockerfiles
Getting setup:
1. If Docker is already running use `Control+C` on a PC or `Command+C` on a mac to end the running Docker container
2. Run `cd ~` to move to the home directory
3. Make the folder to store the Rockerverse Dockerfile `mkdir -p github/rocker-verse`
4. Change to the directory you made with `cd github/rocker-verse`
5. Use `touch` to create the Dockerfile by running `touch Dockerfile`
6. Edit the Dockerfile with nano by running `nano Dockerfile`
```
FROM rocker/verse:3.6.3
## Install CyVerse VICE Depends
RUN apt-get update && apt-get install -y lsb-release wget apt-transport-https python2.7 python-requests curl supervisor nginx gnupg2 libfuse2 nano htop
RUN curl "http://ftp.se.debian.org/debian/pool/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u8_amd64.deb" -O && \
dpkg -i libssl1.0.0_1.0.1t-1+deb8u8_amd64.deb && \
rm libssl1.0.0_1.0.1t-1+deb8u8_amd64.deb
# iCommands
RUN wget https://files.renci.org/pub/irods/releases/4.1.10/ubuntu14/irods-icommands-4.1.10-ubuntu14-x86_64.deb && dpkg -i *.deb
```
After you've saved the Dockerfile, you are ready to build the new container
```
docker build -t myname/rstudio-verse:irods .
```
When it is done building, I test it:
```
docker run -it -e PASSWORD=password -p 8787:8787 myname/rstudio-verse:irods
```
log into the container with username `rstudio` and password `password`
Testing iCommands in the new container, open Terminal
```
rstudio@a5f70859de07:~$ iinit
One or more fields in your iRODS environment file (irods_environment.json) are
missing; please enter them.
Enter the host name (DNS) of the server to connect to: data.cyverse.org
Enter the port number: 1247
Enter your irods user name: <myusername>
Enter your irods zone: iplant
Those values will be added to your environment file (for use by
other iCommands) if the login succeeds.
Enter your current iRODS password:
rstudio@a5f70859de07:~$ ils
```
### Using DockerHub
1. Register for an account at [DockerHub](https://hub.docker.com/)
2. Setup your dockerhub account in the docker command line with `docker login`, this will prompt you for your dockerhub username and password.
3. Now you are ready to push a docker image to your account
4. Check to make sure your dockerhub username matches the tag, generically this would be `username/image:tag-name`, for example if Ryan wanted to push an image to his DockerHub he would tag an image like so `rbartelme/rocker-verse:3.6.3`
5. If you already have an image you can rename the tag to match this format with `docker tag docker-hub-username/container:tag`
6. Push to docker hub (need to have your username in the tag for this to work `docker push username/container-image:tag`
### Building your own CyVerse Applications
CyVerse VICE images and Dockerfiles on GitHub: https://github.com/cyverse-vice/
CyVerse VICE images on Docker Hub: https://hub.docker.com/r/cyversevice
Pull a CyVerse Docker image:
```
FROM cyversevice/rstudio-verse:latest
# Change to root user to install linux system dependencies
#USER root
# install some linux packages
#RUN apt-get update && apt-get install -y cowsay fortune
# Reset the username to RStudio user `rstudio` if you ran as root
#USER rstudio
# install some R packages
RUN R -e "install.packages('raster', dependencies=TRUE)"
```
Build the container
```
docker build -t rstudio:raster
```
Test the container on your VM:
```
docker run -it -p 8787:80 -e REDIRECT_URL=http://<IP_address_of_Atmo_VM>:8787 rstudio:raster
```
---
### Homework:
- Look at Dockerfiles discussed today in class and think about how you might modify one of these images or Dockerfiles to do tasks for yourself on CyVerse
- See the above resources on GitHub and Docker Hub for inspiration and resources to develop your own application
- Cowsay!
Create a Dockerfile
```
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y fortune cowsay lolcat
ENV PATH=/usr/games:${PATH}
ENV LC_ALL=C
ENTRYPOINT fortune | cowsay | lolcat
```
Build your fortune telling cow:
```
docker build -t cowsay:cc21
```
Run it
```
docker run -it cowsay:cc21
```
----