3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 function install_docker_ce
() {
19 # installs and configures Docker CE
20 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
21 echo "Removing previous installation of docker ..."
22 for pkg
in docker.io docker-doc docker-compose podman-docker containerd runc
; do sudo apt-get remove
$pkg; done
23 echo "Installing Docker CE ..."
24 sudo apt-get
-y update
25 sudo apt-get
install -y apt-transport-https ca-certificates software-properties-common gnupg
26 sudo
install -m 0755 -d /etc
/apt
/keyrings
27 curl
-fsSL https
://download.docker.com
/linux
/ubuntu
/gpg | sudo gpg
--dearmor -o /etc
/apt
/keyrings
/docker.gpg
28 sudo
chmod a
+r
/etc
/apt
/keyrings
/docker.gpg
29 echo "deb [arch="$
(dpkg
--print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
30 "$
(.
/etc
/os-release
&& echo "$VERSION_CODENAME")" stable" | \
31 sudo
tee /etc
/apt
/sources.list.d
/docker.list
> /dev
/null
32 sudo apt-get
-y update
33 sudo apt-get
install -y docker-ce
35 echo "Adding user to group 'docker'"
36 sudo groupadd
-f docker
37 sudo usermod
-aG docker
$USER
39 if [ -n "${DOCKER_PROXY_URL}" ]; then
40 echo "Configuring docker proxy ..."
41 if [ -f /etc
/docker
/daemon.json
]; then
42 if grep -q registry-mirrors
/etc
/docker
/daemon.json
; then
43 sudo
sed -i "s|registry-mirrors.*|registry-mirrors\": [\"${DOCKER_PROXY_URL}\"] |" /etc
/docker
/daemon.json
45 sudo
sed -i "s|^{|{\n \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"],|" /etc
/docker
/daemon.json
48 sudo bash
-c "cat << EOF > /etc/docker/daemon.json
50 \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"]
55 if [ -n "${OSM_BEHIND_PROXY}" ] ; then
56 if ! [ -f /etc
/systemd
/system
/docker.service.d
/http-proxy.conf
] ; then
57 sudo mkdir
-p /etc
/systemd
/system
/docker.service.d
58 cat << EOF | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
62 [ -n "${HTTP_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/docker.service.d/http-proxy.conf
63 Environment=\"HTTP_PROXY=${HTTP_PROXY}\"
65 [ -n "${HTTPS_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/docker.service.d/http-proxy.conf
66 Environment=\"HTTPS_PROXY=${HTTPS_PROXY}\"
68 [ -n "${NO_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/docker.service.d/http-proxy.conf
69 Environment=\"NO_PROXY=${NO_PROXY}\"
72 if [ -n "${DOCKER_PROXY_URL}" ] ||
[ -n "${OSM_BEHIND_PROXY}" ] ; then
73 sudo systemctl daemon-reload
74 sudo systemctl restart docker
75 echo "... restarted Docker service"
78 echo "Configuring containerd to expose CRI, use systemd cgroup and use DOCKER_PROXY_URL as registry mirror"
79 sudo
mv /etc
/containerd
/config.toml
/etc
/containerd
/config.toml.orig
2>/dev
/null
80 sudo bash
-c "containerd config default > /etc/containerd/config.toml"
81 sudo
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc
/containerd
/config.toml
82 if [ -n "${DOCKER_PROXY_URL}" ]; then
83 sudo
sed -i "s#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]\n \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"\]\n endpoint = \[\"${DOCKER_PROXY_URL}\"\]\n \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"registry.hub.docker.com\"]\n endpoint = \[\"${DOCKER_PROXY_URL}\"]#" /etc
/containerd
/config.toml
85 sudo systemctl restart containerd
87 [ -z "${DEBUG_INSTALL}" ] ||
! echo "File: /etc/docker/daemon.json" ||
cat /etc
/docker
/daemon.json
88 echo "Testing Docker CE installation ..."
89 sg docker
-c "docker version" || FATAL_TRACK docker_ce
"Docker installation failed. Cannot run docker version"
90 sg docker
-c "docker run --rm hello-world" || FATAL_TRACK docker_ce
"Docker installation failed. Cannot run hello-world"
91 echo "... Docker CE installation done"
92 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
99 while getopts ":D:p:-: P" o
; do
102 OSM_DEVOPS
="${OPTARG}"
105 DOCKER_PROXY_URL
="${OPTARG}"
111 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL
="y" && continue
112 echo -e "Invalid option: '--$OPTARG'\n" >&2
116 echo "Option -$OPTARG requires an argument" >&2
120 echo -e "Invalid option: '-$OPTARG'\n" >&2
129 source $OSM_DEVOPS/common
/logging
131 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
132 echo "DOCKER_PROXY_URL=$DOCKER_PROXY_URL"
133 echo "OSM_BEHIND_PROXY=$OSM_BEHIND_PROXY"