1. create a docker account by visiting – https://cloud.docker.com

2. create a docker repository by clicking create a repository from the docker website

3. open a text editor on Mac (e.g. Atom or Sublime) and create a file named Dockerfile without any extensions. (for e.g. No .txt etc)

4. This post is to push a simple python file to Docker. Use the below commands and paste them in the Dockerfile.

FROM python:3 # This line tells the system to use Python version 3
ADD app.py / # Name of your python file
RUN pip install sense_hat #since this is going to be a Rasp Pi SenseHat, install sense_hat package, in your case any package you are trying to use.
CMD [ “python”, “./app.py” ] # Run your python file from Docker container.

5. app.py – copy and paste below content.

# Script created by KB
# Creates a light alarm using sense hat on raspberry pixels

from sense_hat import SenseHat
from time import sleep
import sys

sense = SenseHat()

red = (255, 0, 0)
green = (0, 255, 0)

while True:
try:
temp = sense.temp
print(‘temp threshold 35’)
if temp >= 35:
pixels = [red for i in range(64)]
print(‘temp alert, threshold crossed: ‘+str(temp)+’ degree C’)
else:
pixels = [green for i in range(64)]
print(‘temp in limit, threshold met: ‘+str(temp)+’ degree C’)
sense.set_pixels(pixels)
sleep(1)
sense.clear()
sleep(1)
except KeyboardInterrupt:
sense.clear()
sys.exit()
6. Python file needs proper indentation, so, make sure when you copy and paste above code it is properly indented and is able to compile.

7. Open terminal in Mac, try to login using your docker credentials using the below command

docker login –username=YOUR_UN –password=YOUR_PWD

8. use the below command to do a docker build on your locatl machine. docker build -t yourbuild .

9. use the below command to do docker build on docker.

docker build -t yourdockername/yourdockerrepo:yourtag .

10. use the below command to push the image

sudo docker push yourdockername/yourdockerrepo:yourtag

How to create and push docker image from mac terminal

Leave a Reply

Your email address will not be published. Required fields are marked *