Table of Contents
1. Install Docker
2. Configure Docker
3. Create an automated deployment script
4. Apply CI/CD tools
Example: Using GitHub Actions
Home Backend Development Golang How to implement automated deployment of Docker on Debian

How to implement automated deployment of Docker on Debian

May 28, 2025 pm 04:33 PM
linux git docker nginx access tool ai shell script

How to implement automated deployment of Docker on Debian

Implementing automated deployment of Docker on Debian systems can be accomplished in a variety of ways. Here are the detailed step guides:

1. Install Docker

First, make sure your Debian system is up to date:

 <code>sudo apt update sudo apt upgrade -y</code>

Next, install the necessary packages to support APT access to the repository over HTTPS:

 <code>sudo apt install apt-transport-https ca-certificates curl software-properties-common -y</code>

Import Docker's official GPG key:

 <code>curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -</code>

Add Docker's official repository address:

 <code>sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"</code>

Update the package index and install Docker Community Edition:

 <code>sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io -y</code>

Start Docker service and set it to boot:

 <code>sudo systemctl start docker sudo systemctl enable docker</code>

2. Configure Docker

To ensure that Docker can run automatically with the system startup, you can use the systemd service:

 <code>sudo systemctl enable docker</code>

3. Create an automated deployment script

You can write a shell script to implement the automated deployment of Docker containers. Here is a basic example script:

 <code>#!/bin/bash</code> Define container name and mirror name<p> CONTAINER_NAME="my_container"
IMAGE_NAME="nginx:latest"</p><h1> Check if the target container is running</h1><p> if docker ps -a | grep -q $CONTAINER_NAME; then
echo "Container $CONTAINER_NAME is already running."
else</p><h1> Start a new container</h1><pre class="brush:php;toolbar:false"> <code>docker run -d --name $CONTAINER_NAME -p 80:80 $IMAGE_NAME echo "Container $CONTAINER_NAME has been started."</code>

fi

Save this script as deploy_docker.sh and give execution permissions:

 <code>chmod x deploy_docker.sh</code>

Execute the script:

 <code>./deploy_docker.sh</code>

4. Apply CI/CD tools

If more complex automated deployment processes are required, CI/CD tools such as Jenkins, GitLab CI/CD, or GitHub Actions can be used. These tools can help you automate the entire process from code pull, build, test and deployment.

Example: Using GitHub Actions

  1. Create a .github/workflows directory in your GitHub project.
  2. Create a new YAML configuration file in this directory, such as deploy-docker.yml:
 <code>name: Deploy Docker</code><p> on:
push:
branches:</p>
  • Main

jobs: build-and-deploy: runs-on: ubuntu-latest

 <code>steps: - name: Pull repository code uses: actions/checkout@v2 - name: Log in to Docker Hub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} - name: Build and push Docker image uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile push: true tags: yourusername/yourimage:latest - name: Deploy to production server run: | ssh -o StrictHostKeyChecking=no ${{ secrets.PRODUCTION_SERVER }} 'bash -s'</code>

  1. Add the necessary Secrets to your project, such as DOCKERHUB_USERNAME, DOCKERHUB_ACCESS_TOKEN and PRODUCTION_SERVER.
  2. Create a deploy_on_production.sh script, which is specifically responsible for deploying Docker containers on production environment servers.

Through the above steps, you can realize the automated deployment of Docker on the Debian system. Depending on actual needs, you can choose the appropriate method and tool.

The above is the detailed content of How to implement automated deployment of Docker on Debian. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1504
276
Solana price forecast for August 2025 Solana price forecast for August 2025 Aug 07, 2025 pm 11:21 PM

There are three scenarios for Solana price forecast in August 2025: 1. In an optimistic scenario, if the network stability improves and the ecology is prosperous, the price can reach $550-$800; 2. In a neutral scenario, the network is stable and the ecology is steadily developing, with a price range of $300-$500; 3. In a pessimistic scenario, if network problems occur frequently, the ecology shrinks and encounters a bear market, the price may fall back to $100-$250; Investors can choose platforms such as Binance, Ouyi, Huobi, Gate.io, KuCoin or Coinbase for trading, which provide good liquidity and security, suitable for different types of investors to participate in the Solana market.

How to use 5,000 yuan to earn 500,000 yuan in the currency circle? How to use 5,000 yuan to earn 500,000 yuan in the currency circle? Aug 07, 2025 pm 08:42 PM

In the field of digital currency, a full range of variables and opportunities, increasing the principal of 5,000 to 500,000 means that one hundred times the asset appreciation needs to be achieved. This is not a simple math game, but a comprehensive test involving cognition, strategy, mentality and execution. It requires participants not to rely solely on luck, but also to have keen market insight and extraordinary risk management capabilities.

What is Bitcoin (BTC)? A brief introduction to what is Bitcoin What is Bitcoin (BTC)? A brief introduction to what is Bitcoin Aug 07, 2025 pm 10:48 PM

Bitcoin (BTC) is a digital asset created and run based on cryptography principles. It does not rely on specific central institutions, such as banks or governments, to issue and manage. Its concept was first proposed in 2008 by an individual or group named "Satoshi Nakamoto" in a paper titled "Bitcoin: A peer-to-peer electronic cash system."

SOL price trend forecast: Will it explode again in 2025? SOL price trend forecast: Will it explode again in 2025? Aug 07, 2025 pm 08:06 PM

Yes, SOL may explode again in 2025. 1) Technology upgrades such as Firedancer launch, which is expected to increase TPS to one million level; 2) New DePIN and AI narratives promote ecological development; 3) On-chain data continues to recover, TVL exceeds US$2 billion; 4) Institutional funds return combined with ETF expectations; 5) If fundamentals and market sentiment cooperate, the price is expected to hit US$250, but you need to be wary of the history of downtime, intensified competition and risk of token selling pressure. Investors should build positions in batches and combine on-chain data dynamic adjustment strategies. The final outbreak depends on the synergistic effect of technology implementation, ecological activity and capital resonance.

August cryptocurrency exchange discount evaluation: new user rewards and handling fee reductions August cryptocurrency exchange discount evaluation: new user rewards and handling fee reductions Aug 08, 2025 pm 11:15 PM

Table of Contents: August Binance (Binance) Exchange Discounts: August Bybit Exchange Discounts: August MEXC Matcha Exchange Discounts: August Bitfinex (Green Leaf) Exchange Discounts: Cryptocurrency Exchange Ranking This article will compile the latest offers from major cryptocurrency exchanges in August 2025, and one article allows readers to enjoy the best benefits. What many newbies in the currency circle don’t know is that most exchanges have hidden application offers, which include: fee reduction (10-20% reduction) new account bonus (can serve as margin, use

What is the future price of MemeFi (MEMEFI currency)? Price forecast for 2025, 2026, 2027-2030 What is the future price of MemeFi (MEMEFI currency)? Price forecast for 2025, 2026, 2027-2030 Aug 08, 2025 pm 11:09 PM

What is the MemeFi currency in the directory? MemeFi gameplay introduction MemeFi (MEMEFI) price forecast MemeFi (MEMEFI) price forecast: EMA cluster and Bollinger band extrusion breakthrough MemeFi (MEMEFI) price forecast: RSI and direction trend momentum MemeFi (MEMEFI) price forecast from 2025 to 2030 MemeFi (MEMEFI) price forecast from 2026 MemeFi (MEMEFI) price forecast from 2027 MemeFi (MEMEFI) price forecast from 2028 MemeFi (MEMEFI) 2

How to make 300,000 yuan with 3,000 yuan in the currency circle? Ultimate actual combat How to make 300,000 yuan with 3,000 yuan in the currency circle? Ultimate actual combat Aug 07, 2025 pm 08:36 PM

From three thousand to three hundred thousand means seeking a hundred times the reward. This is not a fantasy in the crypto world, but it requires the executor to have a very high level of cognition, a tough mindset and precise operation. This is not a comfortable road, but a high-risk and high-reward game. The path to this goal requires careful design and strict implementation.

Bitcoin (BTC) short-term profit settlement 'cooled' and prices remain firmly at the $115,000 mark Bitcoin (BTC) short-term profit settlement 'cooled' and prices remain firmly at the $115,000 mark Aug 08, 2025 pm 11:00 PM

Table of Contents Markets are in a “relative equilibrium state” for the rest of 2025 Bitcoin Outlook is positive Although Bitcoin prices have fallen from all-time highs, Glassnode points out that the current market has entered a “relative equilibrium position”. According to analysis by on-chain data platform Glassnode, as Bitcoin price gradually rebounds after a local low of $112,000, the selling pressure of short-term holders (STH) in profitable state is weakening. In a market report released on Wednesday, Glassnode said that short-term holders (referring to investors who have held the currency for less than 155 days) have significantly "cooled". Data shows that the "spending output profit margin" (SOPR) measuring the selling ratio of recent buy and profitable investors has declined

See all articles