skip to Main Content

I wrote a simple script as follows:

#main.py

def test_function():
    val = input('please enter a number')
    for i in range(int(val)):
        print (i)

I dockerized it and put it in a container, and ran it from there. Everything is working fine.

I have another machine with Linux OS. How can I test this container there?
Do I need to simply copy paste it or what?

2

Answers


  1. You need to install Docker on the other machine, and then push the image to a docker registry (e.g dockerhub / AWS ECR).

    I use ECR. You need to create a registry and then tag your docker image with the url of the registry by running docker tag <source image> <url of the registry>,
    then run docker push <image name>

    and to pull it from the other machine, run docker pull <url of the rigistry>

    Or, you could just simply install docker on the other machine, copy the dockerfile there, and run docker build -t <image name> /path/to/file

    Login or Signup to reply.
  2. There are several abstractions, which you should take use of:

    • language abstraction (python in your case)
    • os abstractions (docker in your case)
    • api abstraction (stdout in your case)

    When it comes to simple functions like yours, there is no reason to test dockerized application twice because docker handles os abstraction very well, and makes your container environment independent (most of the times).

    For your function, you should change output from stdout to other source, and test data, you are putting there with unit test.

    You should do it using same language, and it’s libraries (like PyTest).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search