0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

docker ubuntuでC言語実行環境を構築する

Posted at

学校の授業でC言語を使う予定があったので、dockerの勉強として構築しました。

フォルダ構成

.
├── Dockerfile
├── docker-compose.yml
└── src
    └── (c言語ファイル)

Dockerfileを書く

Dockerfile.
FROM ubuntu:latest

RUN apt-get update && apt-get install -y \
    build-essential \
    mingw-w64

RUN mkdir /workspace
WORKDIR /workspace

docker-compose.ymlを書く

docker-compose.yml
services:
  c-runner:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - type: bind
        source: ./src
        target: /workspace
    tty: true
    command: /bin/bash

実行手順

①プロジェクト直下のディレクトリでdocker-compose up -dでコマンドを実行。
②docker container lsでコンテナが無事立ち上がっているか確認する。
③cd srcでsrcフォルダに移動する
④c言語のファイルを作成

test.c
#include <stdio.h>

int main() {
    printf("Hello, world!!\n");
    return 0;
}

⑤ gcc -o test test.c | ./testでコマンドを実行しHello, world!!と表示されれば成功。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?