This summerizes my notes during playing with docker, building an ubuntu environment.
On our Window PC, we like to have an Linux environment, for
- Unix file management workflow,
- scripting and
- Python development.
We will not use WSL neither WSL2, but Docker - this, we can transfer to another host system - to provide an image and a container that offer a Linux environment, with
- TTY only
- work as a user, e.g. docker, including sudo rights
- with its home directory /home/docker
- that /home/docker shall be directly accessible from the host system's native tools, e.g. via File Explorer:
- at a defined directory, by docker bind or volume (works_)
- at a Windows drive letter, by Unix Samba (t.b.d.)
- the environment shall be usable via VScode and Windows PowerShell
- use zsh a shell, including auto_complete & auto_suggestion
- provide fancy prompt with p10k and font MesloLGS Nerd Font Mono
Let us create a docker image from ubuntu, so that docker will provide a docker container that we can use as our Python Development Environment and some Unix Scripting.
- Docker Desktop
- for Windows see: Install Docker Desktop on Windows
- for Mac, see: Install Docker Desktop on Mac
- for Linux, see: Install Docker Desktop on Linux
- VScode, see: Download Visual Studio Code
Define some folders for our working environment by chosing any folder at your host machine OS (e.g. Windows) and create a structure like:
PythonEnv_with_Ubuntu_Docker/
|-- .dockerignore
|-- Dockerfile
\-- README.md
home_docker/ # anywhere at your host
|
| **************************************
| * This is the *
| * my_ubuntu_cont: /home/docker/ *
| * --> host: home_docker/ *
| **************************************The ubuntu_cont with its user docker will use a dedicated bind volume, i.e. the users directory /home/docker/ that is linked to the host's OS (e.g. Windows) directory home_docker/.
-
Go to directory with Dockerfile, e.g. docker/ubuntu/
PythonEnv_with_Ubuntu_Docker/ # go here |-- .dockerignore |-- Dockerfile \-- README.md
-
check the content of the Dockerfile:
FROM ubuntu:latest # see: https://stackoverflow.com/questions/36611052/install-pip-in-docker RUN DEBIAN_FRONTEND=noninteractive \ apt-get update && apt-get -y install \ zsh \ git curl wget lynx \ iputils-ping lshw net-tools \ nano bc gawk htop eza fzf bat neovim stow \ sudo \ python3.12 python3-pip pipenv \ tzdata \ unminimize # correct timezone ENV TZ=Europe/Berlin RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # --------------------------- user:passwd RUN useradd docker && echo "docker:docker" | chpasswd RUN usermod --shell /usr/bin/zsh -aG sudo docker RUN usermod --shell /usr/bin/zsh -aG sudo root # ------------------------------------- user:group RUN mkdir -p /home/docker && chown -R docker:docker /home/docker USER root RUN zsh
-
Build a new image ubuntu_img and tag it (-t) with new image name:
docker build -t ubuntu_img . # notice the dot at the end
You can see all images, with:
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE mubuntu_img latest daedc675771f 30 minutes ago 947MB
To create a container ubuntu_cont for the user docker that is at a directory of your host (e.g. Windows): Go to host's directory _home_docker/ !!
PythonEnv_with_Ubuntu_Docker/
|-- .dockerignore
|-- Dockerfile
\-- README.md
home_docker/ # go here
|
| **************************************
| * This is the *
| * my_ubuntu_cont: /home/docker/ *
| * --> host: home_docker/ *
| **************************************Proceed with create the container, if you are here:
PS ...\docker\home_docker>for Windows PS or cmd prompt, a one-liner
docker container create -it --name ubuntu_cont --user docker -v $PWD/:/home/docker ubuntu_img zshfor Unix/Mac cmd prompt, multiple lines
docker container create -it \
--name ubuntu_cont \
--user docker \
-v $PWD/:/home/docker \
ubuntu_img \
zshChanges in a running container will only stay as long as the container ist up and running. If you stop the container, that changes will be lost with the next re-start, but you can commit a container and build a new image from that container (see: docker container commit), with this all your changes will stay.
Changes that are done in a volume or a bind location - as we do here for user docker - will stay and be there after re-starting the container.
- You may unminimize the ubuntu installation by
sudo unminimize- Sometimes you like to reconfigure the prompt, do so by
p10k configureEnsure that the MesloLGS Nerd Font Mono ist configured at your PS and VScode
- PS: Go to Einstellungen > Standardwerte > Darstellung > Schriftart > set to:
MesloLGS Nerd Font Mono - VScode: Goto File > Preferences > Settings > at "Search settings" input: Terminal:Integrated:Font > set to:
MesloLGS Nerd Font Mono
-
Oh-my-zsh and some plugins
- see: Oh-my-zsh
- see: Oh my zsh - with some plugins
If you already have a container ubuntu_cont:
Note:
the container ubuntu_cont knows: it will use the volume, defined with
-v $PWD/:/home/dockeror
-v home_docker_vol:/home/dockerso you do NOT need to start at a dedicated host's directory (as with step 1.)
Start ubuntu_cont with
docker start ubuntu_contIf container is running: exec with login:
docker exec -it ubuntu_cont loginAfter ubuntu_cont is running, you can attach to, with: docker attach ubuntu_cont and your prompt will show:
PS ... \docker\home_docker> docker start ubuntu_cont
ubuntu_cont
PS ... \docker\home_docker> docker attach ubuntu_cont
╭─ ∅ / ─────────────────────────────────────────────────────────────────
╰─❯ cd
╭─ ~ ───────────────────────────────────────────────────────────────────
╰─❯ -
Start the container from
PS ... \docker\home_docker> docker start ubuntu_cont ubuntu_cont
-
Attach - better exec - to a running container via
PowerShell 7.4.6 PS ... > docker start ubuntu_cont ubuntu_cont PS ... > docker exec -it ubuntu_cont login e4215510551d login: docker Password: docker Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 5.15.153.1-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro ╭─ ~ ─────────────────────────────────────────────────────────────── ╰─❯ <ENTER> ╭─ ~ ─────────────────────────────────────────────────────────────── ╰─❯
Sometimes you like to make your own image from the container that you are working with - Google docker commit
# TODO:
# TODO:
# 



