当前位置: 首页 > news >正文

Docker - Create my own Ubuntu image and run it on Windows

1. Pull the ubuntu:24.04 image.

 

2. Set shared directory so that I can operate on files in both Windows and the container:

1

 

3. Create the Dockerfile file:

FROM ubuntu:24.04# Install sudo and zsh
RUN apt-get update && apt-get install -y sudo zsh
# Create non-root user 'zzh' with sudo priviledges
RUN useradd -ms /bin/zsh zzh && usermod -aG sudo zzhUSER zzh
WORKDIR /home/zzh# Set zsh as default shell
SHELL ["/bin/zsh", "-c"]

 

4. Build image:

PS D:\VSCodeWorkspace\ZUBT> docker build -t ubuntu-zzh:24.04 .

 

5. Create the docker-compose.yml file:

services:ubuntu:image: ubuntu-zzhcontainer_name: ZUBTtty: truestdin_open: truevolumes:- D:/Docker/Volumes/ZUBT/home/zzh:/home/zzhcommand: tail -f /dev/null

 

6. Start a container:

PS D:\VSCodeWorkspace\ZUBT> docker compose up -d
[+] Running 1/1✘ ubuntu Error pull access denied for ubuntu-zzh, repository does not exist or may require 'docker login': denied: requested access to the resource...               5.7s 
Error response from daemon: pull access denied for ubuntu-zzh, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
PS D:\VSCodeWorkspace\ZUBT>

 

When you run docker compose up -d, Compose looks on Docker Hub unless it finds a locally built image with the exact same tag and you’ve told it how to build or reference it.

 

Update the docker-compose.yml file, adding the tag:

services:ubuntu:image: ubuntu-zzh:24.04container_name: ZUBTtty: truestdin_open: truevolumes:- D:/Docker/Volumes/ZUBT/home/zzh:/home/zzhcommand: tail -f /dev/null

 

PS D:\VSCodeWorkspace\ZUBT> docker compose up -d
[+] Running 2/2✔ Network zubt_default  Created                                                                                                                                      0.0s ✔ Container ZUBT        Started

 

7. Get a shell inside:

PS D:\Docker> docker exec -it ZUBT /bin/zsh
2109969aee88%