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.
  1. Docker Install
    1. Links
    2. Common commands
    3. Windows
    4. Linux: Ubuntu
    5. Docker in Docker: Ubuntu
    6. To Dos
    7. Notes
    8. Image Scripts


Links


Common commands





Windows

Install and setup

You  might have to do this:

    If installing on Windows

  1. We assume you already have an account and are logged in. 
    1. Download and install Docker Desktop for Windows: https://www.docker.com/products/docker-desktop
  2. There should be a Docker Desktop icon on your desktop. Run it. 
    1. It will ask you accept terms. 
    2. 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

  1. Start the Windows command prompt where you can type commands into a window.
  2. Do these commands:
    1. docker pull Ubuntu
      1. This download the base image for Ubuntu. 
    2. docker images
      1. This lists on the images available. You should see "Ubuntu".
    3. docker ps -a
      1. Show all containers, even if they are not running
    4. docker  create -it --name odendata_base Ubuntu 
      1. This creates and starts our container.  "-it" keeps the container running even if there is nothing to do. 
    5. docker start odendata_base
      1. run the container
    6. docker ps -a
      1. Show all containers, even if they are not running. "odendata_base" should be listed in the last column.
      2. You should see it running.
    7. docker exec -it odendata_base bash
      1. Connect to container 
    8. 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

    9. Stop the container.
      1. docker stop odendata_base
    10. docker commit odendata_base odendata_base_image
      1. Save the container as a base image. Now it is on your local computer you can use for more containers. 
  3. Create a new container using your base image. 
    1. docker images
      1. odendata_base_image should be in there.
    2. docker create -it -p 8001:80 -p 2200:22 -p 3106:3306 --name local_odendata -v "c:\tmp";/windows odendata_base_image
      1. This creates the container ports and shared directory.
    3. docker start local_odendata 
      1. start container
    4. docker exec -it local_odendata bash
      1. connect to container
    5. In the docker instance start apache and ssh.
      1. service apache2 start
      2. service sshd start
    6. Test the web ports in Windoze:
      1. On your browser go to http:://127.0.0.1:8801/
        1. You should see the Apache start page. 
      2. 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

    1. Linux Docker section
    2. Docker in Docker section? Why? Because its useless and cool.
    3. 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.