2020/07/15

How to install Docker on Ubuntu 18.04 and Build specific image by Dockerfile

Docker Installation
$ sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

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

$ sudo apt update
$ sudo apt install -y docker-ce docker-ce-cli containerd.io

Check Docker version and status
$ docker -v
$ docker info


Build a specific Ubuntu image and run as container
$ nano Dockerfile

FROM ubuntu:18.04
MAINTAINER (´_ゝ`)

#Install Java and Python
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y wget unzip curl usbutils nano git
RUN apt-get install -y aapt openjdk-11-jdk-headless
RUN apt-get install python-dev python-protobuf protobuf-compiler python-virtualenv python-pip

# Install Android ADB and Fastboot
RUN apt-get install -y android-tools-adb android-tools-fastboot
RUN wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
RUN unzip platform-tools-latest-linux.zip
RUN rm -rf /usr/lib/android-sdk/platform-tools/
RUN mv platform-tools/ /usr/lib/android-sdk
RUN rm platform-tools-latest-linux.zip

# Install PowerShell for Ubuntu 18.04
RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update
RUN apt-get install -y powershell
RUN rm packages-microsoft-prod.deb

# Install Azure CLI
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN az extension add --name azure-devops

save and exit

$ docker build -t ImageName .
$ docker run -d -h "HostName" --name ContainerName --privileged -v /dev/bus/usb:/dev/bus/usb -it ImageName
$ docker ps -a
$ docker container ls
$ docker exec --user="root" -it ContainerName /bin/bash

1 則留言: