Container Best Practices

From Computer Science Wiki
Jump to navigation Jump to search

Use reputable container registries

  • You are giving the container root level access to your system make sure it comes from a trusted source.

Make sure the image is up to date

  • Outdated Operating system cores or outdated applications need to be updated regularly.
  • Especially applications that have existing vulnerabilities
  • These are prime targets for hackers who will have knowledge of the system they are exploiting

Validate what ports are open

  • Many containers when enabled will automatically interact with your system's firewall
  • This led to a number of service databases being exposed on the internet
  • Double check what ports are mapped from docker to the host
    • docker port -a
  • If you are setting up a new container environment you can request Techstaff scan your system's ports to ensure that only necessary ports are open.
  • Unless you specifically need a port to be externally accessible we strongly recommend binding them to local host
    • example: docker run -p 127.0.0.1:6379:6379/tcp redis

Check what services are installed

  • Some containers when downloaded may come with unneeded services installed.
  • Double check that everything running is actually needed.
  • Consider using a multistage dockerfile if you need some tools in an intermediate version to strip out unneeded services

Change default passwords

  • Many containers are designed to serve as a test or proof of concept and come with a default database password or admin password
  • If you plan on using the Container for a long period of time or in production these passwords need changed to protect your data

Change default IP ranges

  • Docker Uses the 172.16 range of IP's by default
  • It overlaps with Virginia Tech's Internal IP range and can make the server inaccessible
  • More information can be found on the wiki at HowTo:Docker 172 Fix

Run services as user instead of Root if possible

  • Try setting the application to run as a non-root user
    • USER <username>
  • You can also try to run the container as a specified user at run time
    • docker run --user <uid>:<gid> imagefile