my docker tutorial

0 what’s docker

docker instruction article

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

windows-docker-install link

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

在這裏插入圖片描述
solution link

在這裏插入圖片描述

在這裏插入圖片描述
在這裏插入圖片描述
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

ubuntu在沒有vi情況下,更新源的方法

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章