0 what’s docker
I created an docker image which installed ubuntu, ssh, python2&3, pipenv.
You can get the latest docker image by:
docker pull ahope2019/ubuntu_python3_tool
In this article, I first installed the docker in MAC system and created the image. Then I installed docker and run this image in the windows system.
In addition I recorded the bugs I faced during the whole process and the way I used to fix them.
Following are the steps I did to create this image.
1 add mirror
2. find exist image
find an image in dock hub.
https://hub.docker.com/r/fnndsc/ubuntu-python3/dockerfile
3. get&run image
docker pull fnndsc/ubuntu-python3
docker run -itd --name ubuntu_python3 -p 9977:22 d755
docker exec -it <container_id> /bin/bash
docker image ls
docker ps
docker ps -a
docker rm <container_id>
docker logs <container_id>
$ docker exec -it 8df /bin/bash
root@8df195cdd716:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@8df195cdd716:/# python
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
4. apt-get update error
I can’t use apt-get to install software and I can’t use vim.
So I use the following commands to modify “sources.list”.
echo “deb http://old-releases.ubuntu.com/ubuntu/ maverick main restricted universe multiverse”>>/etc/apt/sources.list
echo “deb http://old-releases.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse”>>/etc/apt/sources.list
echo “deb http://old-releases.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse”>>/etc/apt/sources.list
5. install software
apt-get install sudo
*在sources.list文件中加入了非ubuntu官方源,所以认为加入源是不可信任的。
解决方法
导入该源公钥。E084DAB9为上图中公钥后八位
gpg --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
gpg --export --armor 40976EAF437D05B5 | sudo apt-key add -
apt-get install sudo
sudo passwd root
apt-get install openssh-server –fix-missing
service ssh start
vi /etc/ssh/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin yes
service ssh restart
apt-get install vsftpd –fix-missing
修改配置文件/etc/vsftpd.conf
listen=YES
local_enable=YES
write_enable=YES
anonymous_enable=YES
service vsftpd start
6. save image
docker commit 容器名 新镜像名
docker save -o 保存的文件名 新镜像名
docker load -i 镜像文件名
push to docker hub
$ docker tag ubuntu_python3_xw:latest ahope2019/ubuntu_python3_tool:init_env
$ docker push ahope2019/ubuntu_python3_tool:init_env
docker rmi $(docker image ls -a -q)
7. mount local directory
docker run -itd --name ubuntu_tool -p 9977:22 -v /Users/xiongwei/Downloads/my_project/github_directory/debug_tool:/usr/src/debug_tool 008
apt-get install python3-venv --fix-missing
8. windows install docker
8.1 Set share driver
docker run -itd --name ubuntu_tool -p 9977:22 -v C:/work/code/my_project/py/debug_tool:/usr/src/debug_tool 008
fireware detected
Then remove and run container again.
8.2 Use powershell to start image
docker exec --privileged=true -it a6 /bin/bash
Install python2&3, and pipenv
安装python/pip
apt-get update
sudo apt install python 安装python2,因为系统已经安装了python3
sudo apt install python-pip 指定python2的pip,使用为pip
sudo apt install python3-pip 指定为python3的pip,使用为pip3
安装pipenv
pip install pipenv
Install virtual env for project
#####创建python3环境
$ pipenv --three
#####创建python2环境
$ pipenv --two
##### remove env
$ pipenv --rm
#####support utf-8
$ export LC_ALL=C.UTF-8
$ export LANG=C.UTF-8
#####enter into virtual env
$ pipenv shell
#####show venv path
$ pipenv --venv
#####exit env
$exit
#####install package
$ pipenv install flask
#####import requirements.txt into pipfile
$ pipenv install --skip-lock
$ pipenv install -r requirements.txt
#####use your own directory to run pipenv
# 1. create the .venv with command
PIPENV_VENV_IN_PROJECT=1 pipenv install
# 2. use the follow command to active the pipenv shell in ./venv
PIPENV_VENV_IN_PROJECT=1 pipenv shell
# 3. use "exit" to exit the virtual env
参考文章:
docker搭建ubuntu–python环境
Ubuntu更新软件源出现GPG error
https://stackoverflow.com/questions/25291686/ubuntu-can-not-install-software-properties-common