2024年4月27日

HYEOS

随事而为

Docker install Debian

2 min read

之前用docker安装magento2之后进行配置网站时,原环境是centos,我个人习惯于debian的环境配置,便直接pull了debian的最新版本开始环境配置:

## DOCKER IMAGE

for the example we can use Debian. Search in Docker hub the Image https://hub.docker.com/_/debian.

Now, download the image:

下载debian的docker最新镜像

docker pull debian

## CONTAINER

Now, we need to set up and run the image:

if went not download the image before, the debian image could be downloaded y create the Container.

pull下载完之后,启动镜像并进入容器内

docker run --name debian -e LANG=C.UTF-8 -it debian /bin/bash -l

with the command we obtain the bash shell section in the Container named to debian, with the hostname set to debian and locale to C.UTF-8.

## SETUP ENVIRONMENT

Now we can update and install some packages necessary:

更新软件包的列表,并安装本地环境包

apt update && apt upgrade --yes && apt install sudo locales --yes

configure datetime zone:

重新配置时区

dpkg-reconfigure tzdata

if we want to change the locale:

更改本地语言环境

rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 export LANG=en_US.utf8

## CREATE A USER

Now we need create a user into Container, it user in the Container should coincide with we user in the Host:

adduser
添加普通用户

user_name

将新建的用户赋予sudo权限

echo "user_name ALL=PASSWD: ALL" > /etc/sudoers.d/user_name

we user should coincide in the Host and Container since if we share volumes we will not have permission problems.

login and continue setting our Container.

su -

user_name

Now we can install some packages for make we development environment.

安装常用组件
sudo apt install curl nginx wget zip vim htop git build-essential cmake --yes
安装并户用ssh服务
sudo apt install openssh-client openssh-server --yes
/etc/init.d/ssh start

leave for Container CRTL-d until we finish at Host.

## CREATE IMAGE

after we have install all necessary in our Container we could save the Container as a new Image and remove the Container:

docker image ls
查看当前所有的镜像

for using username could have a user in Docker Hub and login in the Host using “docker login” command (read https://docs.docker.com/get-started/part2/#share-your-image).

将当前正在运行或是之前配置过的debian打包成新的镜像debiannewversion(任意取名)
docker commit debian debiannewversion

NOTE: from my username, docker commit debian username/debian:develop

将旧的原先下载的debian镜像删除(如果后续有用可以留着不删除)
docker rmi debian

## VOLUMES

使用新的镜像启动容器,并映射本地目录,以待之后创建网站时使用

 
docker run --name debiannew -v /var/www/html/debian:/var/www/html -it debiannewversion /bin/bash
 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注