Docker Image එකක් Build කරන විදිහ
Docker භාවිතා කරන විට application එක container එකක් තුළ run කරන්න Docker Image එකක් අවශ්ය වෙනවා. Docker Image කියන්නේ container එකක් create කරන්න භාවිතා කරන template එකක්. Docker Image එක build කිරීම සඳහා සාමාන්යයෙන් Dockerfile කියන configuration file එක භාවිතා කරනවා. Dockerfile එක තුළ application එක run වෙන්න අවශ්ය instructions define කරනවා.
Dockerfile කියන්නේ Docker image build කිරීම සඳහා භාවිතා කරන text file එකක්.
මෙම file එක තුළ define කරනවා:
Docker build process එකේදී Dockerfile එක read කරලා Docker Image එක create වෙනවා.
Node.js application එකක් සඳහා simple Dockerfile එකක් මෙහෙම ලියන්න පුළුවන්.
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "app.js"]
මෙහි:
Dockerfile create කරලා ඉවර වුනාට පස්සේ Docker image build කරන්න පහත command එක භාවිතා කරනවා.
docker build -t my-app-image .
මෙහි:
Build process එක complete වුනාම Docker image එක system එකේ store වෙනවා.
Build කරපු Docker images list එක බලන්න මේ command එක භාවිතා කරන්න පුළුවන්.
docker images
මෙම command එකෙන් system එකේ තිබෙන Docker images list එක display වෙනවා.
Build කරපු image එකෙන් container එක run කරන්න පහත command එක භාවිතා කරනවා.
docker run -p 3000:3000 my-app-image
මෙහි application එක container එක තුළ run වෙනවා.