在Ubuntu环境下使用Docker容器,可以按照以下步骤进行:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl 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 docker-ce
sudo systemctl start docker
sudo systemctl enable docker
sudo docker --version
或者运行一个简单的Docker容器来测试Docker是否正常工作:
sudo docker run hello-world
docker pull hello-world
docker run -itd --name my_container hello-world
docker ps
docker stop my_container
docker rm my_container
docker rmi hello-world
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose.yml
):version: '3.8'
services:
web:
image: nginx:alpine
ports:
- "80:80"
db:
image: postgres:latest
environment:
POSTGRES_DB: mydatabase
POSTGRES_USER: user
POSTGRES_PASSWORD: password
docker-compose up -d
docker-compose ps
docker-compose down
以上步骤涵盖了在Ubuntu环境下安装Docker、使用Docker容器以及使用Docker Compose的基本流程。