Docker Manual

# view all images
docker ps

1. Start Nginx

docker run nginx

// run in backend
docker run -d -p nginx

// bridge port to run
docker run -d -p 8080:80 nginx

2. MySQL

// install mysql
docker pull mysql

docker pull mysql:8.0

// create root database
docker run -d 
-p 3306:3306 
-e MYSQL_ROOT_PASSWORD=abc  
-e MYSQL_DATABASE=123 
mysql:latest



//access mysql
docker exec -it mysql_db mysql -u root -p

docker stop mysql_db
docker rm mysql_db

docker pull mysql:8.0

docker run -d \
  -e MYSQL_ROOT_PASSWORD=root123 \
  -e MYSQL_DATABASE=mydb \
  -e MYSQL_USER=user1 \
  -e MYSQL_PASSWORD=pass123 \
  --name mysql_db \
  -p 3306:3306 \
  -v /opt/workspace/db/mysql/openerp:/var/lib/mysql \
   mysql:8.0

2.2  重启mysql

# Restart container
docker restart mysql_openerp

# Check container logs
docker logs -f mysql_openerp

3.   go to continer

 docker exec -it 72(container ID) bash

4.  git clone from github

// update to new

cd /opt/openerp
git fetch origin
git reset --hard origin/dev

This will replace all local changes with the dev branch from GitHub.

Safe if you don’t need local modifications.
sudo mkdir -p /opt/openerp
sudo chown -R $USER:$USER /opt/openerp
sudo chmod -R 777 /opt/openerp


cd /opt/openerp
touch Dockerfile

// edit file
cd /opt/openerp
touch Dockerfile


nano Dockerfile



Press Ctrl + O → Enter → Ctrl + X

5. Create Dockerfile 

sudo mkdir -p /opt/openerp
sudo chown -R $USER:$USER /opt/openerp
sudo chmod -R 777 /opt/openerp

6. Build dockerfile

 docker build -t app /opt/app

docker build -t openerp .

docker run -d --name openerp -p 8080:8080 openerp


docker run -d \
-p 8888:8888 \
-v /opt/openerp/static:/opt/openerp/static \
--name openerp-dev openerp


#optional
-v /opt/workspace/openerp/application-dev.yml:/opt/app/application.yml \
-e SPRING_PROFILES_ACTIVE=dev \

 


7.  view all continers

docker ps -a

docker logs -f openerp

8. log

# Viewing Docker Logs (All Containers)
docker logs $(docker ps -q)

docker logs --details openerp

# 最新100
docker logs <container> --tail 100
# 第一行
docker logs <container> | head -n 1

9. 进入 App Container 测试

docker exec -it openerp bash

curl http://localhost:8080

 在Container内部查看资源是否存在

docker exec -it openerp bash
ls /opt/openerp/static
0 = normal exit

1 = application error

127 = file not found (wrong CMD)

137 = killed (OOM)

143 = graceful shutdown

10. Install JDK

sudo apt update
sudo apt install openjdk-21-jdk -y

temurin-XX-jdk = absolute newest version


which java

eadlink -f $(which java)


export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

Stop Docker

docker stop 容器ID

Delete Docker

docker rmi image[:tag]

11 通過openssl製作證書

mkdir -p /opt/workspace/worker_myerp/ssl

openssl req -x509 -newkey rsa:4096 -nodes \
  -keyout /opt/workspace/worker_myerp/ssl/privkey.pem \
  -out /opt/workspace/worker_myerp/ssl/fullchain.pem \
  -days 365

12 製作腳本

chmod +x /opt/workspace/worker_myerp/script_build_myerp

13 install node npm

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

node -v
npm -v

### CI/CD Pipeline with Docker Integration Best Practices and Setup Guide Continuous Integration (CI) services like Travis CI provide seamless integration capabilities not only for source control platforms but also support various development tools including Docker[^3]. When integrating Docker into a CI/CD pipeline, several best practices should be considered. #### Choosing the Right Tools For implementing automated workflows within GitLab-CI specifically, utilizing appropriate package management solutions such as Conan can enhance efficiency during deployment phases[^5]. #### Building Efficient Pipelines Using Prompt Engineering Techniques To streamline processes further, applying principles from prompt engineering allows for more effective guidance throughout different stages of the CI process. This approach aims at reducing manual tasks while increasing overall system responsiveness and team output levels[^4]. #### Leveraging Pre-built Images A key aspect involves selecting or creating optimized images tailored towards specific project requirements; for instance, one might opt for an official Python base image which already contains necessary dependencies like version `3.7` installed[^2]. ```yaml stages: - build - test - deploy variables: DOCKER_DRIVER: overlay2 before_script: - docker info build_image: stage: build script: - echo "Building Docker Image" - docker pull python:3.7-slim-buster || true - docker build --tag myapp:$CI_COMMIT_REF_NAME . test_app: stage: test script: - echo "Running Tests Inside Container" - docker run --rm myapp:$CI_COMMIT_REF_NAME pytest deploy_to_production: only: - master when: manual stage: deploy script: - echo "Deploying Application To Production Environment" - docker tag myapp:$CI_COMMIT_REF_NAME registry.example.com/myapp:latest - docker push registry.example.com/myapp:latest ``` This YAML configuration demonstrates how to set up a basic yet powerful CI/CD flow using Docker containers alongside GitLab's built-in features. Each job corresponds to distinct lifecycle events—from building custom software packages via specified versions all way until pushing final artifacts onto remote registries ready for live usage. --related questions-- 1. How does choosing between community edition versus enterprise editions impact Docker-based projects? 2. What advantages do pre-configured Docker images offer over manually setting up environments inside pipelines? 3. Can you explain what role continuous delivery plays compared to just doing continuous integration alone? 4. In what ways could advanced scripting improve upon this sample .gitlab-ci.yml file provided here? 5. Why would someone prefer using Conan over other dependency managers in conjunction with Dockerized applications?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值