Docker Install
by Mark Nielsen
Copyright June 2021
NOTE: I am being VERY VERY unorthodox. I am putting SEVERAL programs running in a DOCKER instance.
Their way of doing things means you have one DOCKER per service or software. I put all in one which is NOT what you are suppose to do. Don't care. Let me shoot myself in the foot.
Although I agree with their way 99% of the time, I want this to be easy for me and
I want to show how it can be done.
- Docker Install
- Links
- Common commands
- Windows
- Linux: Ubuntu
- Docker in Docker: Ubuntu
- To Dos
- Notes
- Image Scripts
Links
- docker Desktop for Windows:
https://www.docker.com/products/docker-desktop
- https://docs.docker.com/desktop/windows/
- https://hub.docker.com/signup
-
https://www.youtube.com/watch?v=fqMOX6JJhGo
-
https://www.youtube.com/watch?v=fqMOX6JJhGo
-
https://docs.docker.com/engine/reference/commandline/docker/
-
https://towardsdatascience.com/15-docker-commands-you-should-know-970ea5203421
- https://docs.docker.com/engine/reference/commandline/docker/
Common
commands
- Get started and get an account
- Read https://www.docker.com/get-started
- Download Docker Desktop and install. Run it after is has
downloaded.
- Read:
https://hub.docker.com/editions/community/docker-ce-desktop-windows
- First get an account: https://hub.docker.com/signup
- Sing in: https://id.docker.com/login
Windows
Install and setup
You might have to do this:
If installing on Windows
- We assume you already have an account and are logged
in.
- Download and install Docker Desktop for Windows:
https://www.docker.com/products/docker-desktop
- There should be a Docker Desktop icon on your desktop. Run
it.
- It will ask you accept terms.
- It will start a program. We will ignore this.
Start using docker
We will ignore the program. We will use the DOS prompt or command
prompt. If you wish to go through the tutorial do so.
You also can do the tutorial at
https://docs.docker.com/get-started
-
To start the tutorial: :
-
In the command prompt: docker run -d -p 80:80 docker/getting-started
-
This will download an image and run a container off of the image.
- After it is running in the your browsers go to http://localhost
-
The container is running on port 80 the default web port on your
computer.
- To use some commands
- docker images
- docker ps
- My container id was: c0d78a6c20d7
- docker ps -a
- Stop the container when done:
- docker stop c0d78a6c20d7
- You will have to change the container id c0d78a6c20d7
to your container id under "docker ps" and it should be the first
column.
- docker ps -a
- Shows the container exists, but says when it exited or
stopped.
- Start the Windows command prompt where you can type
commands into a window.
- Do these commands:
- docker pull Ubuntu
- This
download the base image for Ubuntu.
- docker images
- This lists on the images available. You should see
"Ubuntu".
- docker ps -a
- Show all containers, even if they are not running
- docker create -it --name odendata_base
Ubuntu
- This creates and starts our container. "-it"
keeps the container running even if there is nothing to do.
- docker start odendata_base
- run the container
- docker ps -a
- Show all containers, even if they are not running.
"odendata_base" should be listed in the last column.
- You should see it running.
- docker exec -it odendata_base bash
- Connect to container
- Install packages I suggest and other commands. It might
ask you some questions like timezone questions.
apt-get update
# these updates will take a "long" time
apt-get install -y emacs screen apache2 tmux man
# start and stop services. Will be useful for apache, mysqld, ssh, and maybe others.
# postfix might ask internet questions
apt-get install -y ubuntu-system-service postfix apt-get install -y gnupg gnupg1 gnupg2 software-properties-common python2 sudo
a2enmod alias auth_basic authn_dmb cgi env filter headers include proxy request rewrite status vhost_alias
service apache2 restart
# install mariadb because I said so
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
add-apt-repository 'deb http://mirrors.accretive-networks.net/mariadb/repo/10.3/ubuntu bionic main'
apt update
apt install -y mariadb-server python3-pip
service mariadb start
sleep 2
service mysql status
mysql -u root -e "select 'database is up', now()"
apt-get install python3-mysqldb
# install monogdb because I said so
unminimize
apt-get install -y wget curl
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
apt-get update
apt-get install -y mongodb-org
# For some reason service won't start mongodb
/usr/bin/mongod --config /etc/mongod.conf
mongo -eval "db.adminCommand('listDatabases')"
apt-get install openssh-server
service ssh start
useradd -m -s /bin/bash mark
echo 'mark:mark' | sudo chpasswd
- Stop the container.
- docker stop odendata_base
- docker commit odendata_base odendata_base_image
- Save the container as a base image. Now it is on your
local computer you can use for more containers.
- Create a new container using your base image.
- docker images
- odendata_base_image should be in there.
- docker create -it -p 8001:80 -p 2200:22 -p 3106:3306 --name local_odendata -v "c:\tmp";/windows odendata_base_image
- This creates the container ports and shared directory.
- docker start local_odendata
- start container
- docker exec -it local_odendata bash
- connect to container
- In the docker instance start apache and ssh.
- service apache2 start
- service sshd start
- Test the web ports in Windoze:
- On your browser go to http:://127.0.0.1:8801/
- You should see the Apache start page.
- On Putty or other program ssh to the host 127.0.0.1 and port 2200
and see if you can login as "mark" with password "mark".
For me I used this as a Dev/QA/Staging server for my
production box. I verify everything looks good and sync it to
production.
Linux:
Ubuntu
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world
Docker
in Docker: Ubuntu
TODO: someday and for no reason
To Dos
- Linux Docker section
- Docker in Docker section? Why? Because its useless and cool.
- Make init 1 start properly for services to start correctly. It is intentionally
made so you can't do it. I saw notes on how to undo the restrictions.