Docker and Docker-compose one-click installation tutorial (supports online and offline)

Docker and Docker-compose one-click installation tutorial (supports online and offline)

Shell Script

#!/bin/sh
# Current directory CURRENT_DIR=$(
 cd "$(dirname "$0")"
 pwd
)

#Install docker 
if which docker >/dev/null; then
 echo "Docker is already installed, skip the installation step"
 docker -v
 echo "Start Docker"
 service docker start 2>&1 | tee -a ${CURRENT_DIR}/install.log
else
 if [[ -d "$CURRENT_DIR/docker" ]]; then
  echo "... install docker offline"
	 cp $CURRENT_DIR/docker/centos-local.tgz /root/
	 cd /root && tar -xvzf centos-local.tgz 
  cd /root/docker-ce-local &&rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm
  mkdir -p /etc/yum.repos.d/repobak && mv /etc/yum.repos.d/CentOS* /etc/yum.repos.d/repobak
  cp $CURRENT_DIR/docker/docker-ce-local.repo /etc/yum.repos.d/docker-ce-local.repo
  cd /root/docker-ce-local &&createrepo /root/docker-ce-local && yum makecache
	 cd $CURRENT_DIR/docker/ &&yum install -y container-selinux-2.9-4.el7.noarch.rpm &&yum install -y docker-ce
	 echo "... start docker"
	 sudo systemctl start docker 2>&1 | tee -a ${CURRENT_DIR}/install.log
	 echo '{"registry-mirrors":["https://registry.docker-cn.com"]}'>/etc/docker/daemon.json
	 cat /etc/docker/daemon.json
	 service docker restart
 else
  echo "... install docker online"
  curl -fsSL https://get.docker.com -o get-docker.sh 2>&1 | tee -a ${CURRENT_DIR}/install.log
  sudo sh get-docker.sh 2>&1 | tee -a ${CURRENT_DIR}/install.log
  echo "... start docker"
  service docker start 2>&1 | tee -a ${CURRENT_DIR}/install.log
 fi
fi

##Install Latest Stable Docker Compose Release
if which docker-compose >/dev/null; then
 echo "Docker Compose is detected to be installed, skipping the installation step"
 docker-compose -v
else
 if [[ -d "$CURRENT_DIR/docker-compose" ]]; then
  echo "... offline installation of docker-compose"
	 cd $CURRENT_DIR/docker-compose/ && cp docker-compose /usr/local/bin/
	 chmod +x /usr/local/bin/docker-compose
	 docker-compose -version
	 echo "... Offline installation of docker-compose successful"
 else
  echo "... install docker-compose online"
  curl -L "https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 2>&1 | tee -a ${CURRENT_DIR}/install.log
  chmod +x /usr/local/bin/docker-compose
  ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
	 docker-compose -version
	 echo "... Successfully installed docker-compose online"
 fi
fi

If the script is copied and used, the following error is reported

insert image description here

Please execute

sed -i 's/\r$//' installDocker.sh
chmod +x installDocker.sh

In case of poor network conditions, offline installation is recommended. Please download the following package first.

Offline installation package link: https://pan.baidu.com/s/1ANDM5v-Z1zmljekc4djAdQ

Extraction code: 39dm

This is the end of this article about one-click installation of docker and docker-compose (supports online and offline). For more relevant docker and docker-compose installation content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker-compose tutorial installation and quick start
  • Docker Compose installation methods in different environments
  • Two simplest ways to install docker-compose
  • Detailed example of installing docker and docker-compose
  • Detailed steps for installing and setting up Docker-compose
  • Practical notes on installing Jenkins with docker-compose

<<:  Why is UTF-8 not recommended in MySQL?

>>:  Style trigger effect of web page input box

Recommend

Implementation code for using mongodb database in Docker

Get the mongo image sudo docker pull mongo Run th...

mysql startup failure problem and scenario analysis

1. One-stop solution 1. Problem analysis and loca...

Solution to garbled display of Linux SecureCRT

Let's take a look at the situation where Secu...

jquery+springboot realizes file upload function

This article example shares the specific code of ...

Detailed explanation of the JVM series memory model

Table of contents 1. Memory model and runtime dat...

In-depth understanding of Vue's data responsiveness

Table of contents 1. ES syntax getter and setter ...

How to use docker to deploy spring boot and connect to skywalking

Table of contents 1. Overview 1. Introduction to ...

Detailed explanation of transactions and indexes in MySQL database

Table of contents 1. Affairs: Four major characte...

HTML tutorial, understanding the optgroup element

Select the category selection. After testing, IE ...

Install multiple versions of PHP for Nginx on Linux

When we install and configure the server LNPM env...

MySql learning day03: connection and query details between data tables

Primary Key: Keyword: primary key Features: canno...

Vue3 Vue Event Handling Guide

Table of contents 1. Basic event handling 2. Send...

Two box models in web pages (W3C box model, IE box model)

There are two types of web page box models: 1: Sta...

About installing python3.8 image in docker

Docker Hub official website 1. Search for Python ...

Detailed explanation of when javascript scripts will be executed

JavaScript scripts can be embedded anywhere in HT...