How to install Docker on Ubuntu

Good Lord, looking for simple and straightforward instructions for installing and configuring Docker on Ubuntu had me googling all over.  Here are some straight forward instructions that you can simply copy and paste.

Open a command prompt and run these commands

sudo apt install docker.io
sudo apt-get install openssl ssl-cert
sudo mkdir /var/docker
cd /var/docker
sudo openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
sudo mkdir /etc/systemd/system/docker.service.d
sudo groupadd docker 
sudo gpasswd -a ${USER} docker 
sudo gedit /etc/systemd/system/docker.service.d/docker.conf &

Add the following to the file opened in gedit:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -D --tls=true --tlscert=/var/docker/cert.pem --tlskey=/var/docker/key.pem -H tcp://127.0.0.1:2376

In your command prompt, continue with running these commands.

sudo systemctl daemon-reload

sudo systemctl restart docker

systemctl status docker.service

Docker should be running.  You should see output from the last status call that looks like this:

your-command-prompt:/var/docker$ systemctl status docker.service
● docker.service - Docker Application Container Engine
 Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
 Drop-In: /etc/systemd/system/docker.service.d
 └─docker.conf
 Active: active (running) since Wed 2017-03-01 11:33:15 CST; 8s ago
 Docs: https://docs.docker.com
 Main PID: 16141 (dockerd)
 Tasks: 17
 Memory: 15.3M
 CPU: 294ms
 CGroup: /system.slice/docker.service
 ├─16141 /usr/bin/dockerd -H fd:// -D --tls=true --tlscert=/var/docker/cert.pem --tlskey=/var/docker/key.pem -H tcp://127.0.0.1:2376
 └─16148 containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --r

When running a docker pull command you may get an error like:

Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Be sure to run the docker pull with sudo like

sudo docker pull whatever/project:1.1.1-11

 

Very long string

Sometimes you need to test input with a long string and it is useful to easily see the index of each position so that you can see how much is read or tuncated or whatever.  Here is a handy string that I use.  It is divided up into 10 character blocks with no special characters or spacing (to see how wrapping will work or not work in some cases).  Each block starts with an “L” and ends with an “I” with “x”s and a number indicating position between.  This particular one is 1100 characters long, but it should be easy to extend or modify as needed.  Copy and paste is hella easier than making this by hand or using random characters that don’t indicate position easily.


Lxxxxxx10ILxxxxxx20ILxxxxxx30ILxxxxxx40ILxxxxxx50ILxxxxxx60ILxxxxxx70ILxxxxxx80ILxxxxxx90ILxxxxx100ILxxxxx110ILxxxxx120ILxxxxx130ILxxxxx140ILxxxxx150ILxxxxx160ILxxxxx170ILxxxxx180ILxxxxx190ILxxxxx200ILxxxxx210ILxxxxx220ILxxxxx230ILxxxxx240ILxxxxx250ILxxxxx260ILxxxxx270ILxxxxx280ILxxxxx290ILxxxxx300ILxxxxx310ILxxxxx320ILxxxxx330ILxxxxx340ILxxxxx350ILxxxxx360ILxxxxx370ILxxxxx380ILxxxxx390ILxxxxx400ILxxxxx410ILxxxxx420ILxxxxx430ILxxxxx440ILxxxxx450ILxxxxx460ILxxxxx470ILxxxxx480ILxxxxx490ILxxxxx500ILxxxxx510ILxxxxx520ILxxxxx530ILxxxxx540ILxxxxx550ILxxxxx560ILxxxxx570ILxxxxx580ILxxxxx590ILxxxxx600ILxxxxx610ILxxxxx620ILxxxxx630ILxxxxx640ILxxxxx650ILxxxxx660ILxxxxx670ILxxxxx680ILxxxxx690ILxxxxx700ILxxxxx710ILxxxxx720ILxxxxx730ILxxxxx740ILxxxxx750ILxxxxx760ILxxxxx770ILxxxxx780ILxxxxx790ILxxxxx800ILxxxxx810ILxxxxx820ILxxxxx830ILxxxxx840ILxxxxx850ILxxxxx860ILxxxxx870ILxxxxx880ILxxxxx890ILxxxxx900ILxxxxx910ILxxxxx920ILxxxxx930ILxxxxx940ILxxxxx950ILxxxxx960ILxxxxx970ILxxxxx980ILxxxxx990ILxxxx1000ILxxxx1010ILxxxx1020ILxxxx1030ILxxxx1040ILxxxx1050ILxxxx1060ILxxxx1070ILxxxx1080ILxxxx1090ILxxxx1100I

Derpy pathing

So, today I learned from a typo, that the GAE dev app server treats pathing defined in the @ApiMethod annotation differently than the cloud server.  In the dev app server, a path like either

path = “/endpoint”

path = “endpoint”

will resolve to

/_ah/api/whatevername/v1/endpoint

Where as the cloud GAE will resolve it as either

/_ah/api/endpoint

or

/_ah/api/whatevername/v1/endpoint

respectively.

This had me scratching my head for a while, but it is an interesting thing to remember and it may have some useful applications.

How to set up a proxy server on Google Compute (GCE)

There are times when a proxy server is necessary.  This article will not go into what a proxy server is or why you might need one, but this will give you step by step instructions on how to set up the squid proxy server on a Google Compute Engine (GCE) server.  This document assumes that you have a Google Cloud account and that you know how to set up a GCE server with Ubuntu.  Lines in a Fixed Width Font are commands that should be entered into the command shell.

This can be run on a GCE that has other things on it, but for personal use, a simple GCE f1-micro (1 vCPU, 0.6 GB memory) should be more than enough power.  Start your GCE and SSH into the machine to get a command line then do these simple steps.

  • Install squid
    • sudo apt install squid3
  • Install apache utils
    • sudo apt-get install apache2-utils
    • This Installs the htpasswd utility that allows for creating password files.
  • Copy the default configuration file to back it up.
    • sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.original
  • Delete the old configuration file
    • sudo rm /etc/squid/squid.conf
    • This configuration file is ridiculously huge and has way more than any simple case would need.  We will just back it up and make a new one with only the information that we need.
  • Make a new configuration files
    • sudo vi /etc/squid/squid.conf
  • Enter this in the config file
    • auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
      auth_param basic realm proxy
      acl authenticated proxy_auth REQUIRED
      http_access allow authenticated

      # Choose the port you want. Default is 3128, but we set it to 8888
      http_port 8888

    • The first bit (4 lines) sets squid to require passwords
    • The last bit configures squid to use port 8888.  You can change this to anything you want.
    • Save the file in vi with [esc]:wq
  • Set up the username and password
    • sudo htpasswd -c /etc/squid/passwords [username]
    • Replace [username] with any username you want to use
    • You will be asked to enter and reenter a password for the username that you entered.  make sure they match.
  • Restart the squid service
    • sudo systemctl restart squid.service

You now have a proxy server.  🙂  To use it, you will need to find the external IP address for this GCE and use that along with the port that you set (8888 in this example) and the username and password that you set.

To make life easier, you may want to set an alias for starting squid.  To do that, do the following:

  • Open your bashrc file
    • vi ~/.bashrc
  • Scroll to the bottom of the file and add this line:
    • alias startsquid='sudo systemctl restart squid.service'
  • Save the file
    • [esc]:wq
  • reload your bashrc file so that you can use the new alias
    • . ~/.bashrc
    • that’s (period)(space)~/.bashrc
  • now you can restart it with the alias.
    • startsquid