DEV Community

Dockerizing a Simple Python Process

jess unrein on November 16, 2018

This is part two in a series on taking a simple Python project from local script to production. In part one I talked about a gotcha I ran into when...
Collapse
 
mhausenblas profile image
Michael Hausenblas

Thanks for putting this together! One thing I'd strongly suggest to do is to define a USER in your Dockerfile. If you don't do this, the container (typically) unnecessarily runs as root, which is a big anti-pattern. Unfortunately, we still find way over half of the images on Dockerhub not defining a user due to a lack of education. See also canihaznonprivilegedcontainers.info where we provide some more background.

Collapse
 
thejessleigh profile image
jess unrein • Edited

I had no idea but this is great information. I will update this tutorial and the sample images on dockerhub so I’m not helping perpetuate an anitpattern. Thank you!

Collapse
 
mhausenblas profile image
Michael Hausenblas

Thank you and KUTGW!

Collapse
 
daften profile image
Dieter Blomme

Nice write-up :)

Why push an image and not use the docker hub functionality to build images? Is there a specific reason for that?

Collapse
 
thejessleigh profile image
jess unrein

Pushing an image to Dockerhub makes it available in a wider variety of contexts because other sources can pull it down. Later in this series I'm going to talk about using Docker images for AWS Fargate tasks, and I need to make the Docker image available in a public registry for that.

I'm definitely doing things here and there in these tutorials that might be immediately unnecessary, but are laying groundwork for future tutorials.

Collapse
 
daften profile image
Dieter Blomme

But if I use docker hub to build my images, other sources can pull it down too right? Or am I wrong about that? :s
I'm talking about this: docs.docker.com/docker-hub/builds/

Thread Thread
 
thejessleigh profile image
jess unrein

Oh, I completely misunderstood your comment. Sorry!

There's no reason you couldn't build an image from a github or bitbucket repository, but part of the point of this tutorial is to introduce Dockerhub as a concept, and this is a simpler, more isolated experience, in my opinion. If you are already using Docker and building images from a source control integration, you're probably more advanced than the target audience for this tutorial :)

Thread Thread
 
thejessleigh profile image
jess unrein

Additionally, it seemed a bit complicated to add another integration into this tutorial. It would have gotten overly long. But Using docker hub to build images from an external repository makes a lot of sense, especially if you anticipate the code changing a lot. Both are valid ways to go about things.

Thread Thread
 
daften profile image
Dieter Blomme

Thanks! I know docker hub, but a Dockerfile I need to look up everything, so I'm not that advanced :)

Collapse
 
alekseimarinichenko profile image
AlekseiMarinichenko • Edited

I was following the tutorial and I am stuck on this step:
(base) C:\PycharmProjects\docker-workshop>docker run goodreads-libib-container

The command above produces the next error:

Unable to find image 'goodreads-libib-container:latest' locally
docker: Error response from daemon: pull access denied for goodreads-libib-container, repository does not exist or may require 'docker login': denied: requested access to the resource is
denied.
See 'docker run --help'.

Collapse
 
thejessleigh profile image
jess unrein

I haven't touched the docker repo in a while. It should be publicly accessible, but I'm not sure. Let me take a look at the permissions and see if I can fix that for you. I'll probably get to this in the next couple of days.

Collapse
 
quenchua profile image
quenchua

Thank you so much Jess!
This really helped me a lot

Collapse
 
guntbert profile image
Guntbert

Thank you - great post with (for me) just the right amount of context.

Collapse
 
nikto_crypto profile image
{Deep_Coding }

Please help through setting up docker container with nginx

Collapse
 
thejessleigh profile image
jess unrein

That's a good idea for a future post. I don't have a specific outline for that tutorial at the moment, but I'll work on outlining it. Thanks for the idea!

Collapse
 
arundubey6215 profile image
Samar

Hi Jess, your both articles are really helpful and I am really looking forward to the next AWS series. Keep up with the good work :)