Skip to content

ParinLL/docker-learn

 
 

Repository files navigation

進入lab環境

# Install docker
sudo apt install docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
# 登出重新登入

# Install docker compose
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose

chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
docker compose version

此Lab 目標為

  • 了解與測試Dockerfile
  • 將建立的docker image 上傳到公開的docker hub上
  • 分享您的image
  • Docker compose 範例
Dockerfile: 標準Dockerfile 基本元件
git clone https://github.com/ParinLL/docker-learn.git
cd docker-learn
docker build -t helloworld:v0.1 . --no-cache -f Dockerfile
docker run -it -d -p 8081:8080 helloworld:v0.1
curl http://127.0.0.1:8081/ping  #會出現  Hello World

Dockerfile-builder: 認識builder 作用與好處
docker build -t helloworld:builder . --no-cache -f Dockerfile-builder
docker run -it -d -p 8082:8080 helloworld:builder
curl http://127.0.0.1:8082/ping  #會出現  Hello World

Dockerfile-builder-git: 可結合git 來做為source code版本控管
docker build -t helloworld:builder-git . --no-cache -f Dockerfile-builder-git
docker run -it -d -p 8083:8080 helloworld:builder-git
curl http://127.0.0.1:8083/ping  #會出現  Hello World

Dockerfile-java

docker build -t helloworld:java . --no-cache -f Dockerfile-java
docker run -it --rm helloworld:java

上傳到Docker hub


  1. 請到docker 網站上註冊一個帳號 https://hub.docker.com/

  2. Create Repository --> 取一個名稱helloworld-builder --> Createdockerhub.png

  3. 右上角的帳號地方下拉選單選取 My Profile --> 點選剛剛建立的 Repositories

  4. 看到Repositories 名稱就是您要上傳上去的名稱 ex: helloworld-builder

  5. 接著您可以在docker cmd 位置準備上傳

## 查看剛剛透過dockerfile 產生的images
docker images

	REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
	helloworld                   builder                993df71eb7fe        3 hours ago         10MB

## 替image下一個tag
docker tag helloworld:builder  <ACCOUNT>/helloworld-builder:v0.1
docker images

	REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
	<ACCOUNT>/helloworld-builder      v0.1              993df71eb7fe        3 hours ago         10MB
	helloworld                   builder                993df71eb7fe        3 hours ago         10MB

## 登入docker hub
docker login

	Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head 		over to https://hub.docker.com to create one.
	Username: <ACCOUNT>
	Password:
	WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
	Configure a credential helper to remove this warning. See
	https://docs.docker.com/engine/reference/commandline/login/#credentials-store

	Login Succeeded

## 上傳
docker push <ACCOUNT>/helloworld-builder:v0.1

	The push refers to repository [docker.io/dokfish/helloworld-builder]
	8790a344e219: Pushed
	bd6888799faa: Pushed
	ace0eda3e3be: Pushed
	latest: digest: sha256:041e794a1830abb0a6ba2f7712e09071131b65afb8724d6a5f377387cc64548e size: 951
  1. docker hub網頁上確認 狀態

image.png

  1. 分享給別人使用你的環境

    docker run  <ACCOUNT>/helloworld-builder
    

docker compose

docker compose up -d
curl 127.0.0.1:80/ping

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 64.6%
  • Dockerfile 23.6%
  • Go 11.8%